http://qs321.pair.com?node_id=369559


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

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.

      cheers

      tachyon