From 6d7f4f6675b683475a8eaa8f0f5dff35a0b165f7 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 23 Mar 2016 02:04:32 +0100 Subject: [PATCH] regrtest: add timeout to main process when using -jN libregrtest: add a watchdog to run_tests_multiprocess() using faulthandler.dump_traceback_later(). --- Lib/test/libregrtest/runtest_mp.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Lib/test/libregrtest/runtest_mp.py b/Lib/test/libregrtest/runtest_mp.py index 0ca7dd7a4f5..5e847a096c4 100644 --- a/Lib/test/libregrtest/runtest_mp.py +++ b/Lib/test/libregrtest/runtest_mp.py @@ -1,3 +1,4 @@ +import faulthandler import json import os import queue @@ -151,6 +152,8 @@ class MultiprocessThread(threading.Thread): def run_tests_multiprocess(regrtest): output = queue.Queue() pending = MultiprocessIterator(regrtest.tests) + test_timeout = regrtest.ns.timeout + use_timeout = (test_timeout is not None) workers = [MultiprocessThread(pending, output, regrtest.ns) for i in range(regrtest.ns.use_mp)] @@ -170,11 +173,14 @@ def run_tests_multiprocess(regrtest): finished = 0 test_index = 1 - timeout = max(PROGRESS_UPDATE, PROGRESS_MIN_TIME) + get_timeout = max(PROGRESS_UPDATE, PROGRESS_MIN_TIME) try: while finished < regrtest.ns.use_mp: + if use_timeout: + faulthandler.dump_traceback_later(test_timeout, exit=True) + try: - item = output.get(timeout=timeout) + item = output.get(timeout=get_timeout) except queue.Empty: running = get_running(workers) if running and not regrtest.ns.pgo: @@ -215,6 +221,9 @@ def run_tests_multiprocess(regrtest): regrtest.interrupted = True pending.interrupted = True print() + finally: + if use_timeout: + faulthandler.cancel_dump_traceback_later() running = [worker.current_test for worker in workers] running = list(filter(bool, running))