Last active
August 29, 2015 14:02
-
-
Save Royhb/ce3972ef07cc3a619b23 to your computer and use it in GitHub Desktop.
websocketd exiting a persistent program
This file contains 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
import signal | |
from sys import stdin, stdout | |
import time | |
def clean_exit(): | |
# do whatever is required to clean up, then | |
exit() | |
if __name__ == "__main__": | |
signal.signal(signal.SIGINT, clean_exit) | |
signal.signal(signal.SIGTERM, clean_exit) | |
while True: | |
try: | |
# do productive stuff in this loop | |
# time.sleep() is here just to make a runnable program for demonstration | |
time.sleep(1) | |
except KeyboardInterrupt: | |
clean_exit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment