Skip to content

Instantly share code, notes, and snippets.

@taicki
Created August 14, 2011 22:12
Show Gist options
  • Save taicki/1145374 to your computer and use it in GitHub Desktop.
Save taicki/1145374 to your computer and use it in GitHub Desktop.
import time
import signal
def main():
d = {}
d["stop"] = False
def sighandler(signum, frame):
print signum, frame
d["stop"] = True
signal.signal(signal.SIGINT, sighandler)
while True:
print "foo"
if d["stop"]:
break
time.sleep(10)
if __name__ == "__main__":
import sys
import traceback
try:
main()
except SystemExit:
# when sys.exit(1) is called in main(),
# this except statement will be executed.
raise
except:
traceback.print_exc()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment