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

Re^4: Propagating a Signal from DESTROY

by dpuu (Chaplain)
on Aug 20, 2004 at 16:30 UTC ( #384648=note: print w/ replies, xml ) Need Help??


in reply to Re^3: Propagating a Signal from DESTROY
in thread Propagating a Signal from DESTROY

My reading is that OP did want to be interrupted, but didn't want to jump straight to the end of the program. He wants the interrupt to kill the current eval-block, but then to do some more processing. I could make his example a bit more tricky by requiring that we recover from the interrupt, rather than dying. I.e.

START: my $interrupted = 0; eval { local $SIG{INT} = sub { $interrupted = 1; die }; ... } if ($@) { if ($interrupted) { print "Operation was interrupted by ^C. Press <return> to retry, ^ +C to die\n"; scalar <STDIN>; goto START; } }
If the interrupt hits when the code is in a DTOR, then it will not kill the eval block, and the user will not be asked to retry. In fact, the only effect of the interrupt will be to set $interrupted; and to cause some resource to not be properly cleaned up. We could detect that this happenned by checking:
if ($@) { ... } elsif ($interrupted) { print "interrupted but didn't die. Must have hit ^C during DTOR. Sor +ry.\n"; die "better late than never!\n"; }


Comment on Re^4: Propagating a Signal from DESTROY
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (14)
As of 2014-04-18 19:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (471 votes), past polls