Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Dormus interruptus

by tachyon (Chancellor)
on Jun 25, 2004 at 06:22 UTC ( #369559=note: print w/ replies, xml ) Need Help??


in reply to Dormus interruptus

Couldn't just send a signal to yourself to awaken the sleeping kids/threads? Here is a forking example:

[root@devel3 logtest]# cat test.pl #!/usr/bin/perl $SIG{INT} = sub { print "Caught zap in $$\n"; exit }; if ( my $pid = fork() ) { print "Parent Start\n"; sleep 5; local $SIG{INT} = sub{ print "Parent $$ ignoring zap\n" }; kill 2 => $pid, $$; sleep 10; print "Parent exit!\n"; } else { print "Child start\n"; sleep 10; print "Child exit!\n"; } [root@devel3 logtest]# ./test.pl Parent Start Child start Parent 21850 ignoring zap Caught zap in 21851 Parent exit! [root@devel3 logtest]#

cheers

tachyon


Comment on Re: Dormus interruptus
Download Code
Re^2: Dormus interruptus
by pbeckingham (Parson) on Jun 25, 2004 at 13:15 UTC

    Thank you. I did not think of this, and it does exactly what I wanted, which is to interrupt the sleep calls.

      Usual caveats about signals not being safe but if you use INT you can also catch ^C automaticlly to do a neat cleanup & exit. As an aside I also use a strategy like:

      $dbh = DBI->connect( .... ); END{ $dbh->disconnect if $dbh }

      to ensure clean database disconnects, having exhaused the available supply of connections in the past.

      cheers

      tachyon

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://369559]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2015-07-04 03:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (57 votes), past polls