Using python threading, is it possible to interrupt the main thread without terminate it and ask it to do something else?
For example,
def watch():
while True:
sleep(10)
somethingWrong = check()
if somethingWrong:
raise Exception("something wrong")
try:
watcher = threading.Thread(target=watch)
watcher.start()
doSomething()
except:
doSomethingElse()
In this program the main thread is not affected when an exception is raised in the thread watcher
and keep doSomething
. I want the exception raised in the child thread to propogate to the main thread and make the main thread doSomethingElse
.