Skip to content

Instantly share code, notes, and snippets.

@Royhb
Last active August 29, 2015 14:02
Show Gist options
  • Save Royhb/ce3972ef07cc3a619b23 to your computer and use it in GitHub Desktop.
Save Royhb/ce3972ef07cc3a619b23 to your computer and use it in GitHub Desktop.
websocketd exiting a persistent program
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