Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
09f2e6f9
Commit
09f2e6f9
authored
Jul 26, 2012
by
Antoine Pitrou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #15320: Make iterating the list of tests thread-safe when running tests in multiprocess mode.
Patch by Chris Jerdonek.
parent
707bd4e3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
12 deletions
+31
-12
Lib/test/regrtest.py
Lib/test/regrtest.py
+28
-12
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/test/regrtest.py
View file @
09f2e6f9
...
...
@@ -550,16 +550,7 @@ def main(tests=None, testdir=None, verbose=0, quiet=False,
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,
failfast=failfast, match_tests=match_tests)
)
yield (test, args_tuple)
pending = tests_and_args()
pending = MultiprocessTests(tests)
opt_args = support.args_from_interpreter_flags()
base_cmd = [sys.executable] + opt_args + ['-m', 'test.regrtest']
def work():
...
...
@@ -567,10 +558,16 @@ def main(tests=None, testdir=None, verbose=0, quiet=False,
try:
while True:
try:
test
, args_tuple
= next(pending)
test = next(pending)
except StopIteration:
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,
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
...
...
@@ -622,7 +619,7 @@ def main(tests=None, testdir=None, verbose=0, quiet=False,
test_index += 1
except KeyboardInterrupt:
interrupted = True
pending.
close()
pending.
interrupted = True
for worker in workers:
worker.join()
else:
...
...
@@ -766,6 +763,25 @@ def findtests(testdir=None, stdtests=STDTESTS, nottests=NOTTESTS):
tests.append(modname)
return stdtests + sorted(tests)
# We do not use a generator so multiple threads can call next().
class MultiprocessTests(object):
"""A thread-safe iterator over tests for multiprocess mode."""
def __init__(self, tests):
self.interrupted = False
self.lock = threading.Lock()
self.tests = tests
def __iter__(self):
return self
def __next__(self):
with self.lock:
if self.interrupted:
raise StopIteration('tests interrupted')
return next(self.tests)
def replace_stdout():
"""Set stdout encoder error handler to backslashreplace (as stderr error
handler) to avoid UnicodeEncodeError when printing a traceback"""
...
...
Misc/NEWS
View file @
09f2e6f9
...
...
@@ -378,6 +378,9 @@ Extension Modules
Tests
-----
- Issue #15320: Make iterating the list of tests thread-safe when running
tests in multiprocess mode. Patch by Chris Jerdonek.
- Issue #15230: Adopted a more systematic approach in the runpy tests
- Issue #15300: Ensure the temporary test working directories are in the same
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment