Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: On timing out with ALRM

by xdg (Monsignor)
on Jul 25, 2007 at 16:20 UTC ( #628711=note: print w/replies, xml ) Need Help??


in reply to On timing out with ALRM

It's not very elegant, but what about adding a lexical flag that gets set in your alarm handler?

{ my $timed_out = 0; local $SIG{ ALRM } = sub { $timed_out++; die 'timeout' }; alarm( MAX_SECONDS ); eval { molasses_in_january(); alarm( 0 ); }; if ( $@ ) { die $@ if ! $timed_out; handle_timeout(); } }

-xdg

Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://628711]
help
Chatterbox?
[LanX]: White House indicates it could find funds to train 1 million teachers ...
[LanX]: ...no wait
[LanX]: White House indicates it could find funds to train and arm 1 million teachers!
LanX relieved...
[Discipulus]: too much guns in schools? throw more gun at schools! professors in arms
LanX thinks teachers nowadays need every possible mean to defend against their annoying students.

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (9)
As of 2018-02-23 11:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    When it is dark outside I am happiest to see ...














    Results (301 votes). Check out past polls.

    Notices?