[Python-checkins] cpython (3.2): Try harder to reap dangling threads in test.support.reap_threads().

antoine.pitrou python-checkins at python.org
Fri Jul 15 22:45:19 CEST 2011


http://hg.python.org/cpython/rev/6a221b6b81ee
changeset:   71365:6a221b6b81ee
branch:      3.2
parent:      71361:2bedea96de60
user:        Antoine Pitrou <solipsis at pitrou.net>
date:        Fri Jul 15 22:29:44 2011 +0200
summary:
  Try harder to reap dangling threads in test.support.reap_threads().

files:
  Lib/test/support.py |  19 +++++++++++++------
  Misc/NEWS           |   2 ++
  2 files changed, 15 insertions(+), 6 deletions(-)


diff --git a/Lib/test/support.py b/Lib/test/support.py
--- a/Lib/test/support.py
+++ b/Lib/test/support.py
@@ -24,9 +24,15 @@
 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 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):
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -67,6 +67,8 @@
 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'

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list