Created
July 6, 2016 02:53
-
-
Save ericdorsey/a123b2501708e2044ccead878b557675 to your computer and use it in GitHub Desktop.
Python SIGTERM handling
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
# https://docs.python.org/2/library/signal.html#signal.signal | |
import signal | |
import sys | |
import os | |
def signal_term_handler(signal, frame): | |
if signal == 15: | |
print("got SIGTERM") | |
sys.exit(0) | |
else: | |
print("signal received: {0}").format(signal) | |
# Exit "other than normal" | |
sys.exit(1) | |
# Monitor for SIGTERM signal | |
signal.signal(signal.SIGTERM, signal_term_handler) | |
# Generate a SIGTERM | |
os.kill(os.getpid(), signal.SIGTERM) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment