in reply to Re: When to use sigtrap, when to assign to %SIG?
in thread When to use sigtrap, when to assign to %SIG?
local $SIG{INT} is a rather strange thing to attempt because that implies that CTRL-C has different meanings at different places in the code. I figure this is a "bad" idea.
It makes sense if you have a block of code that must be completed either in its entirety or not at all, to temporarily disable interrupts. For example, you want to remove a row from one database table and add a corresponding row to another database table. You don't want your code to be interrupted and leave the operation in an incomplete state.
OK, so you'd normally use SQL transactions for that, but what if these two tables are in two different databases, on two different servers, at two different sites?
Easy enough to locally override $SIG{INT}, to catch Ctrl+C and rather than exiting immediately, set an $interrupt_caught variable, and then when it is safe, check $interrupt_caught and exit.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: When to use sigtrap, when to assign to %SIG?
by Marshall (Canon) on Jan 04, 2012 at 05:45 UTC | |
Re^3: When to use sigtrap, when to assign to %SIG?
by afoken (Chancellor) on Jan 03, 2012 at 19:19 UTC |