Created
August 14, 2011 22:12
-
-
Save taicki/1145374 to your computer and use it in GitHub Desktop.
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 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