Python - Signal Handling
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) #----------...)
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:
"""