Try:
import threading import time class ThreadWorker(threading.Thread): def run(self): print "Statement from a thread!" raise Dead class Main: def __init__(self): print "initializing the thread" t = ThreadWorker() t.start() time.sleep(2) print "Did it work?" class Dead(Exception): pass Main()
The above code gives the following results:
> initializing the thread > Statement from a thread! > Exception in thread > Thread-1: Traceback (most recent call last): File > "C:\Python27\lib\threading.py", line 551, in __bootstrap_inner > self.run() File ".\pythreading.py", line 8, in run > raise Dead Dead > ----- here the interpreter sleeps for 2 seconds ----- > Did it work?
So, the answer to your question is that the raised exception causes only the thread in which it is located, and not the entire program.
Bo milanovich
source share