Skip to content

Instantly share code, notes, and snippets.

@AndrewFarley
Forked from honza/sigterm.py
Created June 7, 2018 12:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AndrewFarley/7aa856a8eec9e7d45cb231130c6e5d29 to your computer and use it in GitHub Desktop.
Save AndrewFarley/7aa856a8eec9e7d45cb231130c6e5d29 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