Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re: die through several evals

by kennethk (Abbot)
on Apr 23, 2013 at 16:42 UTC ( #1030194=note: print w/replies, xml ) Need Help??

in reply to die through several evals

I can't check $@ or override eval function to propagate die.
Why can't you check $@? This sounds like an artificial constraint. Why can't you simply branch and die if the eval fails, e.g.
local $SIG{ALRM} = sub{die "Timeout hit\n"}; eval { eval { magick_die; }; if ($@ and $@ eq "Timeout hit\n") { die $@; } };

You could also fork and run the alarm in the parent thread. Then it really doesn't matter what the flow in the child is.

#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

Replies are listed 'Best First'.
Re^2: die through several evals
by nyaapa (Novice) on Apr 24, 2013 at 08:59 UTC
    because i only have a anonymous sub and i don't know if there any evil in it... i cant modify this sub..
      What sort of tasks/side effects are happening in the subroutines? You may be able to solve your issue with a fork, a la:
      use strict; use warnings; if (my $pid = fork) { eval { local $SIG{ALRM} = sub{die "Timeout hit\n"}; alarm 1; wait; alarm 0; 1; } or do { print $@; kill 9, $pid; } } else { magick_die(); exit; } sub magick_die { my $var = 0; for (1 ... 1000000) { $var++ for 1 .. 1000000; } }

      If you need to pass information back and forth, you could serialize over pipes.

      #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1030194]
Discipulus 3 earthquake between 5.1 and 5.3.. Closed the subway in roma and many schools evacuated: the school of my little daugther was evacuated.. but nobody called us..

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2017-01-18 11:39 GMT
Find Nodes?
    Voting Booth?
    Do you watch meteor showers?

    Results (161 votes). Check out past polls.