File tree Expand file tree Collapse file tree 3 files changed +30
-5
lines changed
Expand file tree Collapse file tree 3 files changed +30
-5
lines changed Original file line number Diff line number Diff line change @@ -236,6 +236,24 @@ def waitingThread():
236236 """ ])
237237 self .assertEqual (rc , 42 )
238238
239+ def test_enumerate_after_join (self ):
240+ # Try hard to trigger #1703448: a thread is still returned in
241+ # threading.enumerate() after it has been join()ed.
242+ enum = threading .enumerate
243+ old_interval = sys .getcheckinterval ()
244+ sys .setcheckinterval (1 )
245+ try :
246+ for i in xrange (1 , 1000 ):
247+ t = threading .Thread (target = lambda : None )
248+ t .start ()
249+ t .join ()
250+ l = enum ()
251+ self .assertFalse (t in l ,
252+ "#1703448 triggered after %d trials: %s" % (i , l ))
253+ finally :
254+ sys .setcheckinterval (old_interval )
255+
256+
239257class ThreadingExceptionTests (unittest .TestCase ):
240258 # A RuntimeError should be raised if Thread.start() is called
241259 # multiple times.
Original file line number Diff line number Diff line change @@ -515,11 +515,14 @@ def __bootstrap_inner(self):
515515 if __debug__ :
516516 self ._note ("%s.__bootstrap(): normal return" , self )
517517 finally :
518- self .__stop ()
519- try :
520- self .__delete ()
521- except :
522- pass
518+ with _active_limbo_lock :
519+ self .__stop ()
520+ try :
521+ # We don't call self.__delete() because it also
522+ # grabs _active_limbo_lock.
523+ del _active [_get_ident ()]
524+ except :
525+ pass
523526
524527 def __stop (self ):
525528 with self .__block :
Original file line number Diff line number Diff line change @@ -371,6 +371,10 @@ Core and builtins
371371- Issue #1537: Changed GeneratorExit's base class from Exception to
372372 BaseException.
373373
374+ - Fix Issue #1703448: A joined thread could show up in the
375+ threading.enumerate() list after the join() for a brief period until
376+ it actually exited.
377+
374378Library
375379-------
376380
You can’t perform that action at this time.
0 commit comments