diff -r 4752fafb579d Lib/test/regrtest.py --- a/Lib/test/regrtest.py Wed Jul 11 19:21:31 2012 +0200 +++ b/Lib/test/regrtest.py Wed Jul 11 13:15:05 2012 -0700 @@ -166,6 +166,7 @@ """ import builtins +import collections import faulthandler import getopt import io @@ -611,17 +612,7 @@ from subprocess import Popen, PIPE debug_output_pat = re.compile(r"\[\d+ refs\]$") output = Queue() - def tests_and_args(): - for test in tests: - args_tuple = ( - (test, verbose, quiet), - dict(huntrleaks=huntrleaks, use_resources=use_resources, - debug=debug, output_on_failure=verbose3, - timeout=timeout, failfast=failfast, - match_tests=match_tests) - ) - yield (test, args_tuple) - pending = tests_and_args() + pending = collections.deque(tests) # thread-safe pops. opt_args = support.args_from_interpreter_flags() base_cmd = [sys.executable] + opt_args + ['-m', 'test.regrtest'] def work(): @@ -629,10 +620,17 @@ try: while True: try: - test, args_tuple = next(pending) - except StopIteration: + test = pending.popleft() + except IndexError: output.put((None, None, None, None)) return + args_tuple = ( + (test, verbose, quiet), + dict(huntrleaks=huntrleaks, use_resources=use_resources, + debug=debug, output_on_failure=verbose3, + timeout=timeout, failfast=failfast, + match_tests=match_tests) + ) # -E is needed by some tests, e.g. test_import # Running the child from the same working directory ensures # that TEMPDIR for the child is the same when @@ -691,7 +689,7 @@ test_index += 1 except KeyboardInterrupt: interrupted = True - pending.close() + pending.clear() for worker in workers: worker.join() else: diff -r 4752fafb579d Misc/NEWS --- a/Misc/NEWS Wed Jul 11 19:21:31 2012 +0200 +++ b/Misc/NEWS Wed Jul 11 13:15:05 2012 -0700 @@ -121,6 +121,9 @@ Tests ----- +- Issue #15320: Make iterating the list of tests thread-safe when running + tests in multiprocess mode. Patch by Chris Jerdonek. + - Issue #15300: Ensure the temporary test working directories are in the same parent folder when running tests in multiprocess mode from a Python build. Patch by Chris Jerdonek.