Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
No such thing as a small change
 
PerlMonks  

Re: END block not excuting when thread interrupted

by jrockway (Acolyte)
on Jul 09, 2006 at 19:33 UTC ( [id://560032]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to END block not excuting when thread interrupted

Why not add a signal handler for $SIG{INT} to the parent? For example, if I add this:
sub sigint { die "Dying."; } $SIG{INT} = \&sigint;
to your program up at the top, everything exits fine on SIGINT, and the end block is executed:
$ perl test.pl processing sleep(0) in thread 1 processing sleep(1) in thread 1 processing sleep(3) in thread 3 processing sleep(0) in thread 4 processing sleep(2) in thread 4 processing sleep(4) in thread 2 processing sleep(0) in thread 1 processing sleep(3) in thread 1 processing sleep(4) in thread 4 processing sleep(5) in thread 3 <C-c> Dying. at test.pl line 25. END block executed A thread exited while 3 threads were running.
You probably want to do something other than die(), but same idea. SIGCHLD (ignored by default) will catch child deaths, if that's what you wanted originally.

Replies are listed 'Best First'.
Re^2: END block not excuting when thread interrupted
by iankorf (Acolyte) on Jul 09, 2006 at 21:19 UTC
    Many thanks jrockway and BrowserUk.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://560032]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.