Skip to content

Instantly share code, notes, and snippets.

@DazWorrall
Created July 29, 2013 10:22
Show Gist options
  • Save DazWorrall/6103417 to your computer and use it in GitHub Desktop.
Save DazWorrall/6103417 to your computer and use it in GitHub Desktop.
What signal was I sent?
#!/usr/bin/env python
import time
import signal
import sys
SIGS = dict((k, v) for v, k in signal.__dict__.iteritems() if v.startswith('SIG'))
def sighandler(signum, frame):
print 'Signal handler called with signal', SIGS[signum]
sys.exit(1)
for i in [x for x in dir(signal) if x.startswith("SIG")]:
try:
signum = getattr(signal,i)
signal.signal(signum,sighandler)
except (RuntimeError, ValueError), e:
print "Skipping %s" % i
if __name__ == '__main__':
while True:
time.sleep(0.5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment