Sto usando Python 2.5 e sto provando a usare un auto-definito excepthook
nel mio programma. Nel thread principale funziona perfettamente. Ma in un thread avviato con il modulo di threading viene chiamato il solito excepthook
.'sys.excepthook' e threading
Ecco un esempio che mostra il problema. Scomporre il commento mostra il comportamento desiderato.
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()
Così, come posso usare la mia excepthook
in un thread?
Grazie - la terza soluzione funziona perfettamente! – Sebastian