diff Lib/test/test_threading.py @ 44871:ffacb44673ea 2.5

Backport of r60190: - Fix Issue #1703448: A joined thread could show up in the threading.enumerate() list after the join() for a brief period until it actually exited.
author Gregory P. Smith <greg@mad-scientist.com>
date Tue, 22 Jan 2008 01:29:11 +0000
parents be107b04c252
children 43fa50b9eb12
line wrap: on
line diff
--- a/Lib/test/test_threading.py	Mon Jan 21 23:35:11 2008 +0000
+++ b/Lib/test/test_threading.py	Tue Jan 22 01:29:11 2008 +0000
@@ -3,6 +3,7 @@
 import test.test_support
 from test.test_support import verbose
 import random
+import sys
 import threading
 import thread
 import time
@@ -201,6 +202,24 @@
             t.join()
         # else the thread is still running, and we have no way to kill it
 
+    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
+        old_interval = sys.getcheckinterval()
+        sys.setcheckinterval(1)
+        try:
+            for i in xrange(1, 1000):
+                t = threading.Thread(target=lambda: None)
+                t.start()
+                t.join()
+                l = enum()
+                self.assertFalse(t in l,
+                    "#1703448 triggered after %d trials: %s" % (i, l))
+        finally:
+            sys.setcheckinterval(old_interval)
+
+
 def test_main():
     test.test_support.run_unittest(ThreadTests)