Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re^2: Propagating a Signal from DESTROY

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

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

The problem with that approach is, of course, that you need to litter your code with checks of your flag-variable. If you're using a lot of modules (especially slow ones), then you might need to go through those modules' source code and add these same checks there. That seems incredibly non-scalable.
  • Comment on Re^2: Propagating a Signal from DESTROY

Replies are listed 'Best First'.
Re^3: Propagating a Signal from DESTROY
by TilRMan (Friar) on Aug 20, 2004 at 16:05 UTC
    The delayed-handler approach is only necessary where you don't want to be interrupted. In the OP's case, change from the real signal handler to the delayed one at the very end of the program -- right before the destructors.
      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"; }

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://384641]
[LanX]: oh .bat you mean?
[LanX]: obscure cult ...
[Corion]: LanX: cmd.exe is just another way to launch Perl
[LanX]: I know its a cult... and I repent it every time
[LanX]: But cygwin comes with path problems and powershell requires too much learning for me
[LanX]: eshell in emacs is often my resort in development
[LanX]: Thx found a solution! :)
[Eily]: I wrote "your" instead of "you're" :'(

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (9)
As of 2017-03-27 16:00 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (320 votes). Check out past polls.