Skip to content

Commit 5e1400a

Browse files
authored
bpo-37531: sync regrtest with master branch (GH-16285) (GH-16289)
(cherry picked from commit fb7746d)
1 parent 50ecedc commit 5e1400a

File tree

2 files changed

+26
-17
lines changed

2 files changed

+26
-17
lines changed

Lib/test/libregrtest/main.py

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@
2121
from test import support
2222

2323

24+
# bpo-38203: Maximum delay in seconds to exit Python (call Py_Finalize()).
25+
# Used to protect against threading._shutdown() hang.
26+
# Must be smaller than buildbot "1200 seconds without output" limit.
27+
EXIT_TIMEOUT = 120.0
28+
29+
2430
class Regrtest:
2531
"""Execute a test suite.
2632
@@ -157,11 +163,6 @@ def display_progress(self, test_index, text):
157163
def parse_args(self, kwargs):
158164
ns = _parse_args(sys.argv[1:], **kwargs)
159165

160-
if ns.timeout and not hasattr(faulthandler, 'dump_traceback_later'):
161-
print("Warning: The timeout option requires "
162-
"faulthandler.dump_traceback_later", file=sys.stderr)
163-
ns.timeout = None
164-
165166
if ns.xmlpath:
166167
support.junit_xml_list = self.testsuite_xml = []
167168

@@ -611,16 +612,24 @@ def main(self, tests=None, **kwargs):
611612

612613
test_cwd = self.create_temp_dir()
613614

614-
# Run the tests in a context manager that temporarily changes the CWD
615-
# to a temporary and writable directory. If it's not possible to
616-
# create or change the CWD, the original CWD will be used.
617-
# The original CWD is available from support.SAVEDCWD.
618-
with support.temp_cwd(test_cwd, quiet=True):
619-
# When using multiprocessing, worker processes will use test_cwd
620-
# as their parent temporary directory. So when the main process
621-
# exit, it removes also subdirectories of worker processes.
622-
self.ns.tempdir = test_cwd
623-
self._main(tests, kwargs)
615+
try:
616+
# Run the tests in a context manager that temporarily changes the CWD
617+
# to a temporary and writable directory. If it's not possible to
618+
# create or change the CWD, the original CWD will be used.
619+
# The original CWD is available from support.SAVEDCWD.
620+
with support.temp_cwd(test_cwd, quiet=True):
621+
# When using multiprocessing, worker processes will use test_cwd
622+
# as their parent temporary directory. So when the main process
623+
# exit, it removes also subdirectories of worker processes.
624+
self.ns.tempdir = test_cwd
625+
626+
self._main(tests, kwargs)
627+
except SystemExit as exc:
628+
# bpo-38203: Python can hang at exit in Py_Finalize(), especially
629+
# on threading._shutdown() call: put a timeout
630+
faulthandler.dump_traceback_later(EXIT_TIMEOUT, exit=True)
631+
632+
sys.exit(exc.code)
624633

625634
def getloadavg(self):
626635
if self.win_load_tracker is not None:

Lib/test/libregrtest/runtest_mp.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,14 +185,14 @@ def mp_result_error(self, test_name, error_type, stdout='', stderr='',
185185
def _timedout(self, test_name):
186186
self._kill()
187187

188-
stdout = sterr = ''
188+
stdout = stderr = ''
189189
popen = self._popen
190190
try:
191191
stdout, stderr = popen.communicate(timeout=JOIN_TIMEOUT)
192192
except (subprocess.TimeoutExpired, OSError) as exc:
193193
print("WARNING: Failed to read worker process %s output "
194194
"(timeout=%.1f sec): %r"
195-
% (popen.pid, exc, timeout),
195+
% (popen.pid, JOIN_TIMEOUT, exc),
196196
file=sys.stderr, flush=True)
197197

198198
self._close_wait()

0 commit comments

Comments
 (0)