diff options
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_socket.py | 3 | ||||
-rw-r--r-- | Lib/test/test_support.py | 23 | ||||
-rw-r--r-- | Lib/test/test_threadedtempfile.py | 4 |
3 files changed, 29 insertions, 1 deletions
diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py index e0aa58cc1c..e773eab066 100644 --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -906,7 +906,10 @@ def test_main(): tests.append(BasicSocketPairTest) if sys.platform == 'linux2': tests.append(TestLinuxAbstractNamespace) + + thread_info = test_support.threading_setup() test_support.run_unittest(*tests) + test_support.threading_cleanup(*thread_info) if __name__ == "__main__": test_main() diff --git a/Lib/test/test_support.py b/Lib/test/test_support.py index 4f89a867ca..2a749386a5 100644 --- a/Lib/test/test_support.py +++ b/Lib/test/test_support.py @@ -453,3 +453,26 @@ def run_doctest(module, verbosity=None): if verbose: print 'doctest (%s) ... %d tests with zero failures' % (module.__name__, t) return f, t + +#======================================================================= +# Threading support to prevent reporting refleaks when running regrtest.py -R + +def threading_setup(): + import threading + return len(threading._active), len(threading._limbo) + +def threading_cleanup(num_active, num_limbo): + import threading + 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 + time.sleep(0.1) + diff --git a/Lib/test/test_threadedtempfile.py b/Lib/test/test_threadedtempfile.py index 459ba3a1e4..974333b486 100644 --- a/Lib/test/test_threadedtempfile.py +++ b/Lib/test/test_threadedtempfile.py @@ -22,7 +22,7 @@ FILES_PER_THREAD = 50 # change w/ -f option import thread # If this fails, we can't test this module import threading -from test.test_support import TestFailed +from test.test_support import TestFailed, threading_setup, threading_cleanup import StringIO from traceback import print_exc import tempfile @@ -48,6 +48,7 @@ class TempFileGreedy(threading.Thread): def test_main(): threads = [] + thread_info = threading_setup() print "Creating" for i in range(NUM_THREADS): @@ -72,6 +73,7 @@ def test_main(): if errors: raise TestFailed(msg) + threading_cleanup(*thread_info) if __name__ == "__main__": import sys, getopt |