Created
April 6, 2012 22:22
-
-
Save honza/2323525 to your computer and use it in GitHub Desktop.
Sigterm handler in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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