Advertisement
rfmonk

signal_getsignal.py

Feb 3rd, 2014
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.70 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. # this is from The Python
  4. # Standard Library by example
  5. # ISBN13: 9780321767349
  6.  
  7. # this was written for signals in OSX
  8. # when you run this on a linux system it
  9. # asks for an integer and complains about
  10. # line 25.
  11. import signal
  12.  
  13.  
  14. def alarm_received(n, stack):
  15.     return
  16.  
  17. signal.signal(signal.SIGALRM, alarm_received)
  18.  
  19. signals_to_names = dict(
  20.     (getattr(signal, n), n)
  21.     for n in dir(signal)
  22.     if n.startswith('sig') and '_' not in n
  23. )
  24.  
  25. for s, name in sorted(signals_to_names.items()):
  26.     handler = signal.getsignal(s)
  27.     if handler is signal.SIG_DFL:
  28.         handler = 'SIG_DFL'
  29.     elif handler is signal.SIG_IGN:
  30.         handler = 'SIG_IGN'
  31.     print '%-10s (%2d):' % (name, s), handler
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement