Python - Signal Handling

From PeformIQ Upgrade
Revision as of 12:48, 25 January 2008 by PeterHarding (talk | contribs) (New page: =Signal Handling in Python= ==Examples== <pre> #!/usr/bin/env python #===================================================================== def shutdown(): sys.exit(99) #----------...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Signal Handling in Python

Examples

#!/usr/bin/env python

#=====================================================================

def shutdown():
   sys.exit(99)

#---------------------------------------------------------------------

def sigTerm(signum, frame):
   "SIGTERM handler"

   print "[sig]  Caught SIGTERM!"

   shutdown()

#---------------------------------------------------------------------

def main():
   signal.signal(signal.SIGTERM, sigTerm)

   while 1:
       time.sleep(1)

#---------------------------------------------------------------------

if __name__ == '__main__' or __name__ == sys.argv[0]:
   try:
      sys.exit(main())
   except KeyboardInterrupt, e:
      print "Interrupted!"
      shutdown()

#---------------------------------------------------------------------

"""
Revision History:

     Date     Who   Description
   --------   ---   --------------------------------------------------
   20031016   plh   Initial implementation

Problems to fix:

To Do:

Issues:

"""