Skip to content

Instantly share code, notes, and snippets.

@adjam
Created December 13, 2016 18:06
Show Gist options
  • Save adjam/50b0ddd5d8213757d17577b00216717a to your computer and use it in GitHub Desktop.
Save adjam/50b0ddd5d8213757d17577b00216717a to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import threading
import time
from queue import Queue
eq = Queue()
class Dead(Exception):
pass
def catcher(target):
try:
target()
except Exception as e:
print("\tstashing exception")
eq.put(e)
def crash():
print("I think I'm gonna hurl")
time.sleep(.2)
raise Dead("Now it's over, I'm dead and I haven't done anything that I want")
def main():
print("He gon' be here soon")
c = threading.Thread(target=catcher(crash))
try:
c.start()
c.join()
exc = eq.get(False)
if exc:
raise exc
print("I got to the end")
except Exception as e:
print("I got interrupterated by a death in the family")
print(e)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment