Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

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 #!/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]# ./ Parent Start Child start Parent 21850 ignoring zap Caught zap in 21851 Parent exit! [root@devel3 logtest]#



Comment on Re: Dormus interruptus
Download Code
Replies are listed 'Best First'.
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.



Log In?

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2015-11-30 07:23 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (764 votes), past polls