-
-
Save AndrewFarley/7aa856a8eec9e7d45cb231130c6e5d29 to your computer and use it in GitHub Desktop.
Sigterm handler in Python
This file contains hidden or 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