]> granicus.if.org Git - python/commitdiff
Try harder to reap dangling threads in test.support.reap_threads().
authorAntoine Pitrou <solipsis@pitrou.net>
Fri, 15 Jul 2011 20:29:44 +0000 (22:29 +0200)
committerAntoine Pitrou <solipsis@pitrou.net>
Fri, 15 Jul 2011 20:29:44 +0000 (22:29 +0200)
Lib/test/support.py
Misc/NEWS

index e2d7ae05a5845983d372473d179beebdee690e8d..2827e8b84230e7209921afa16d6bfbaf1ad14fea 100644 (file)
@@ -24,9 +24,15 @@ import sysconfig
 import logging.handlers
 
 try:
-    import _thread
+    import _thread, threading
 except ImportError:
     _thread = None
+    threading = None
+try:
+    import multiprocessing.process
+except ImportError:
+    multiprocessing = None
+
 
 __all__ = [
     "Error", "TestFailed", "ResourceDenied", "import_module",
@@ -1275,19 +1281,20 @@ def modules_cleanup(oldmodules):
 
 def threading_setup():
     if _thread:
-        return _thread._count(),
+        return _thread._count(), threading._dangling.copy()
     else:
-        return 1,
+        return 1, ()
 
-def threading_cleanup(nb_threads):
+def threading_cleanup(*original_values):
     if not _thread:
         return
     _MAX_COUNT = 10
     for count in range(_MAX_COUNT):
-        n = _thread._count()
-        if n == nb_threads:
+        values = _thread._count(), threading._dangling
+        if values == original_values:
             break
         time.sleep(0.1)
+        gc_collect()
     # XXX print a warning in case of failure?
 
 def reap_threads(func):
index 00bce493a8c10aab2b5f335bf3c4dd5118650d9d..02b59dcf8a290b587427647d789cdef7e3f5b65a 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -67,6 +67,8 @@ C-API
 Tests
 -----
 
+- Try harder to reap dangling threads in test.support.reap_threads().
+
 - Issue #12573: Add resource checks for dangling Thread and Process objects.
 
 - Issue #12549: Correct test_platform to not fail when OS X returns 'x86_64'