Try harder to reap dangling threads in test.support.reap_threads().

This commit is contained in:
Antoine Pitrou 2011-07-15 22:29:44 +02:00
parent c081c0c6a0
commit 707f228b1e
2 changed files with 15 additions and 6 deletions

View file

@ -24,9 +24,15 @@ import sysconfig
import logging.handlers import logging.handlers
try: try:
import _thread import _thread, threading
except ImportError: except ImportError:
_thread = None _thread = None
threading = None
try:
import multiprocessing.process
except ImportError:
multiprocessing = None
__all__ = [ __all__ = [
"Error", "TestFailed", "ResourceDenied", "import_module", "Error", "TestFailed", "ResourceDenied", "import_module",
@ -1275,19 +1281,20 @@ def modules_cleanup(oldmodules):
def threading_setup(): def threading_setup():
if _thread: if _thread:
return _thread._count(), return _thread._count(), threading._dangling.copy()
else: else:
return 1, return 1, ()
def threading_cleanup(nb_threads): def threading_cleanup(*original_values):
if not _thread: if not _thread:
return return
_MAX_COUNT = 10 _MAX_COUNT = 10
for count in range(_MAX_COUNT): for count in range(_MAX_COUNT):
n = _thread._count() values = _thread._count(), threading._dangling
if n == nb_threads: if values == original_values:
break break
time.sleep(0.1) time.sleep(0.1)
gc_collect()
# XXX print a warning in case of failure? # XXX print a warning in case of failure?
def reap_threads(func): def reap_threads(func):

View file

@ -67,6 +67,8 @@ C-API
Tests Tests
----- -----
- Try harder to reap dangling threads in test.support.reap_threads().
- Issue #12573: Add resource checks for dangling Thread and Process objects. - 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' - Issue #12549: Correct test_platform to not fail when OS X returns 'x86_64'