Python - Trap all signals
As of Python 3.5, the signal constants are defined as an enum, enabling a nicer approach:
import signal
catchable_sigs = set(signal.Signals) - {signal.SIGKILL, signal.SIGSTOP}
for sig in catchable_sigs:
signal.signal(sig, print) # Substitute handler of choice for `print`
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 (OSError, RuntimeError) as m: #OSError for Python3, RuntimeError for 2
print ("Skipping {}".format(i))