views:

355

answers:

1

In python 2.6 under Linux, I can use the following to handle a TERM signal:

import signal
def handleSigTERM():
    shutdown()
signal.signal(signal.SIGTERM, handleSigTERM)    

Is there any way to setup a handler for all signals received by the process, other than just setting them up one-at-a-time?

+1  A: 

You could just loop through the signals in the signal module and set them up.

for i in [x for x in dir(signal) if x.startswith("SIG")]:
  try:
    signum = getattr(signal,i)
    signal.signal(signum,sighandler)
  except RunTimeError,m:
    print "Skipping %s"%i
Noufal Ibrahim
Just what I was looking for, thanks!
Justin Ethier
You're welcome. Thanks for fixing the error in the program. :)
Noufal Ibrahim