Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Python SIGTERM handling
# 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