I am using Python 2.5 and trying to use a self-defined excepthook
in my program. In the main thread it works perfectly fine. But in a thread started with the threading module the usual excepthook
is called.
Here is an example showing the problem. Uncommenting the comment shows the desired behaviour.
import threading, sys
def myexcepthook(type, value, tb):
print 'myexcepthook'
class A(threading.Thread, object):
def __init__(self):
threading.Thread.__init__(self, verbose=True)
# raise Exception('in main')
self.start()
def run(self):
print 'A'
raise Exception('in thread')
if __name__ == "__main__":
sys.excepthook = myexcepthook
A()
So, how can I use my own excepthook
in a thread?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…