File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -21,25 +21,41 @@ class ExceptionalThread( threading.Thread ):
2121 joined the thread. If join() times out, no exception will be re reraised even though an
2222 exception might already have occured in run().
2323
24+ When subclassing this thread, override tryRun() instead of run().
25+
2426 >>> def f():
25- ... assert False
27+ ... assert 0
2628 >>> t = ExceptionalThread(target=f)
2729 >>> t.start()
2830 >>> t.join()
2931 Traceback (most recent call last):
3032 ...
3133 AssertionError
34+
35+ >>> class MyThread(ExceptionalThread):
36+ ... def tryRun( self ):
37+ ... assert 0
38+ >>> t = MyThread()
39+ >>> t.start()
40+ >>> t.join()
41+ Traceback (most recent call last):
42+ ...
43+ AssertionError
44+
3245 """
3346
3447 exc_info = None
3548
3649 def run ( self ):
3750 try :
38- super ( ExceptionalThread , self ). run ( )
51+ self . tryRun ( )
3952 except :
4053 self .exc_info = sys .exc_info ( )
4154 raise
4255
56+ def tryRun ( self ):
57+ super ( ExceptionalThread , self ).run ( )
58+
4359 def join ( self , * args , ** kwargs ):
4460 super ( ExceptionalThread , self ).join ( * args , ** kwargs )
4561 if not self .is_alive ( ) and self .exc_info is not None :
You can’t perform that action at this time.
0 commit comments