Skip to content

Instantly share code, notes, and snippets.

@honza
Created April 6, 2012 22:22
Show Gist options
  • Save honza/2323525 to your computer and use it in GitHub Desktop.
Save honza/2323525 to your computer and use it in GitHub Desktop.
Sigterm handler in Python
"""
This snippet shows how to listen for the SIGTERM signal on Unix and execute a
simple function open receiving it.
To test it out, uncomment the pid code and kill the process with:
$ kill -15 pid
"""
import signal
import sys
# import os
# pid = os.getpid()
# print pid
def handler(signum, frame):
print 'Shutting down...'
sys.exit(1)
signal.signal(signal.SIGTERM, handler)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment