Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: How bad is $SIG{__DIE__} really?

by stevieb (Canon)
on Oct 11, 2016 at 13:47 UTC ( [id://1173726]=note: print w/replies, xml ) Need Help??


in reply to How bad is $SIG{__DIE__} really?

I'm not going to speak too much to the bad and/or the good of trapping warnings/die/interrupt with $SIG handlers, because I've used them all.

One frustrating thing though is when you are troubleshooting code when you're expecting something to happen, but then you find someone's trapped __WARN__, __DIE__ and/or INT. You've spent hours trying to figure out why something did or didn't happen to realize you were correct in the first place, but something was doing something not documented.

My advice is when you trap anything that breaks normal flow (all of these handlers affect the entire stack, even code far away), document it within your POD.

From my RPi::WiringPi distribution:

"We also trap $SIG{__DIE__} and $SIG{INT}, so that in the event of a crash, we can reset the Pi back to default settings, so components are not left in an inconsistent state."

This was needed here, as I'm dealing directly with hardware, where if the program crashes, the user needs to be assured that the hardware is reset to its original state (on the Raspberry Pi, the GPIO pins, registers and other items will stay in the state you last left them, crash or not).

Replies are listed 'Best First'.
Re^2: How bad is $SIG{__DIE__} really? (global)
by tye (Sage) on Oct 12, 2016 at 03:36 UTC

    If you clean up in destructors, then you don't have to try to trap global events. Having a non-global thing (such as your module) try to trap global events is usually a pretty bad idea, as the methods for trapping such things don't have built-in support for multiple handlers.

    - tye        

      You're absolutely right tye. I suppose in my case I'd only have to watch for $SIG{INT} (as DESTROY() isn't called on the interrupt signal), and not $SIG{__DIE__}.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2024-04-24 07:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found