diff -r 6b2f703a38c2 Lib/test/test_threading.py --- a/Lib/test/test_threading.py Sun Jan 20 15:50:05 2008 +0100 +++ b/Lib/test/test_threading.py Mon Jan 21 23:36:18 2008 +0100 @@ -236,6 +236,25 @@ class ThreadTests(unittest.TestCase): """]) self.assertEqual(rc, 42) + def test_enumerate_after_join(self): + # Try hard to trigger #1703448: a thread is still returned in + # threading.enumerate() after it has been join()ed. + enum = threading.enumerate + threads = enum() + old_interval = sys.getcheckinterval() + sys.setcheckinterval(1) + try: + for i in xrange(1000): + t = threading.Thread(target=lambda: None) + t.start() + t.join() + l = enum() + self.assertEqual(threads, l, + "#1703448 triggered after %d trials: %s" % (i, l)) + finally: + sys.setcheckinterval(old_interval) + + class ThreadingExceptionTests(unittest.TestCase): # A RuntimeError should be raised if Thread.start() is called # multiple times. diff -r 6b2f703a38c2 Lib/threading.py --- a/Lib/threading.py Sun Jan 20 15:50:05 2008 +0100 +++ b/Lib/threading.py Mon Jan 21 23:36:18 2008 +0100 @@ -524,11 +524,11 @@ class Thread(_Verbose): if __debug__: self._note("%s.__bootstrap(): normal return", self) finally: - self.__stop() try: self.__delete() except: pass + self.__stop() def __stop(self): self.__block.acquire()