Skip to content

Instantly share code, notes, and snippets.

@duhaime
Created June 20, 2019 11:54
Show Gist options
  • Save duhaime/3b9cc9850bc3939af73e415374f20e9a to your computer and use it in GitHub Desktop.
Save duhaime/3b9cc9850bc3939af73e415374f20e9a to your computer and use it in GitHub Desktop.
Signal Listener
# class to gracefully handle sigint / sigterm (SO 18499497)
class SignalListener:
kill_now = False
def __init__(self):
signal.signal(signal.SIGINT, self.exit_gracefully)
signal.signal(signal.SIGTERM, self.exit_gracefully)
def exit_gracefully(self,signum, frame):
self.kill_now = True
listner = SignalListener()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment