diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2015-04-13 19:41:47 +0200 |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2015-04-13 19:41:47 +0200 |
commit | 25f85d4bd58d86d3e6ce99cb9f270e96bf5ba08f (patch) | |
tree | c6b252f8cde6d114360560f412044a5b0e46d999 /Lib/test/script_helper.py | |
parent | f3b990e48c698154fb2eaa990ee22a6962e041ac (diff) | |
download | cpython-git-25f85d4bd58d86d3e6ce99cb9f270e96bf5ba08f.tar.gz |
Issue #23309: Avoid a deadlock at shutdown if a daemon thread is aborted
while it is holding a lock to a buffered I/O object, and the main thread
tries to use the same I/O object (typically stdout or stderr). A fatal
error is emitted instead.
Diffstat (limited to 'Lib/test/script_helper.py')
-rw-r--r-- | Lib/test/script_helper.py | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/Lib/test/script_helper.py b/Lib/test/script_helper.py index 8c599d1b04..b31fc40013 100644 --- a/Lib/test/script_helper.py +++ b/Lib/test/script_helper.py @@ -1,6 +1,7 @@ # Common utility functions used by various script execution tests # e.g. test_cmd_line, test_cmd_line_script and test_runpy +import collections import importlib import sys import os @@ -50,8 +51,12 @@ def _interpreter_requires_environment(): return __cached_interp_requires_environment +_PythonRunResult = collections.namedtuple("_PythonRunResult", + ("rc", "out", "err")) + + # Executing the interpreter in a subprocess -def _assert_python(expected_success, *args, **env_vars): +def run_python_until_end(*args, **env_vars): env_required = _interpreter_requires_environment() if '__isolated' in env_vars: isolated = env_vars.pop('__isolated') @@ -85,12 +90,16 @@ def _assert_python(expected_success, *args, **env_vars): p.stderr.close() rc = p.returncode err = strip_python_stderr(err) - if (rc and expected_success) or (not rc and not expected_success): + return _PythonRunResult(rc, out, err), cmd_line + +def _assert_python(expected_success, *args, **env_vars): + res, cmd_line = run_python_until_end(*args, **env_vars) + if (res.rc and expected_success) or (not res.rc and not expected_success): raise AssertionError( "Process return code is %d, command line was: %r, " - "stderr follows:\n%s" % (rc, cmd_line, - err.decode('ascii', 'ignore'))) - return rc, out, err + "stderr follows:\n%s" % (res.rc, cmd_line, + res.err.decode('ascii', 'ignore'))) + return res def assert_python_ok(*args, **env_vars): """ |