How to handle Python exception in Threads?
In the code given below, a thread is started. The thread waits for few seconds and checks for an event and if it is found, it stops, else an Exception is thrown.
I want to catch this Exception and would need help in doing so.
import threading
import time
def thread(args1, stop_event):
print "start thread"
stop_event.wait(12)
if not stop_event.is_set():
raise Exception("boom!")
pass
try:
t_stop = threading.Event()
t = threading.Thread(target=thread, args=(1, t_stop))
t.start()
time.sleep(15)
print "stop thread!"
t_stop.set()
except Exception as e:
print " It took too long"