diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2009-10-30 17:25:12 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2009-10-30 17:25:12 (GMT) |
commit | 65c9c6426b719d885f12938a2c5ab938558406ab (patch) | |
tree | 4e4dbbf398d78a6bf2003d3a56635b9f0fa7582d /Lib/test/support.py | |
parent | a2d1fe0b843b27130d0e3194ac2f517692e89c85 (diff) | |
download | cpython-65c9c6426b719d885f12938a2c5ab938558406ab.zip cpython-65c9c6426b719d885f12938a2c5ab938558406ab.tar.gz cpython-65c9c6426b719d885f12938a2c5ab938558406ab.tar.bz2 |
Merged revisions 75958 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r75958 | antoine.pitrou | 2009-10-30 18:07:08 +0100 (ven., 30 oct. 2009) | 7 lines
Issue #7222: Make thread "reaping" more reliable so that reference
leak-chasing test runs give sensible results. The previous method of
reaping threads could return successfully while some Thread objects were
still referenced. This also introduces a new private function:
:func:hread._count().
........
Diffstat (limited to 'Lib/test/support.py')
-rw-r--r-- | Lib/test/support.py | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/Lib/test/support.py b/Lib/test/support.py index 0f3e2ee..a7cac4a 100644 --- a/Lib/test/support.py +++ b/Lib/test/support.py @@ -947,24 +947,29 @@ def run_doctest(module, verbosity=None): #======================================================================= # Threading support to prevent reporting refleaks when running regrtest.py -R +# NOTE: we use thread._count() rather than threading.enumerate() (or the +# moral equivalent thereof) because a threading.Thread object is still alive +# until its __bootstrap() method has returned, even after it has been +# unregistered from the threading module. +# thread._count(), on the other hand, only gets decremented *after* the +# __bootstrap() method has returned, which gives us reliable reference counts +# at the end of a test run. + def threading_setup(): - import threading - return len(threading._active), len(threading._limbo) + import _thread + return _thread._count(), -def threading_cleanup(num_active, num_limbo): - import threading +def threading_cleanup(nb_threads): + import _thread import time _MAX_COUNT = 10 - count = 0 - while len(threading._active) != num_active and count < _MAX_COUNT: - count += 1 - time.sleep(0.1) - - count = 0 - while len(threading._limbo) != num_limbo and count < _MAX_COUNT: - count += 1 + for count in range(_MAX_COUNT): + n = _thread._count() + if n == nb_threads: + break time.sleep(0.1) + # XXX print a warning in case of failure? def reap_threads(func): @functools.wraps(func) |