[Python-checkins] To fix the random failed test cases of test___xxsubinterpreters in multiprocess. (GH-27240)
ambv
webhook-mailer at python.org
Thu Jul 29 13:05:57 EDT 2021
https://github.com/python/cpython/commit/9101b39e67c2437e88c0ad6b57aafd48ab08d431
commit: 9101b39e67c2437e88c0ad6b57aafd48ab08d431
branch: main
author: Hai Shi <shihai1992 at gmail.com>
committer: ambv <lukasz at langa.pl>
date: 2021-07-29T19:05:49+02:00
summary:
To fix the random failed test cases of test___xxsubinterpreters in multiprocess. (GH-27240)
files:
M Lib/test/test__xxsubinterpreters.py
diff --git a/Lib/test/test__xxsubinterpreters.py b/Lib/test/test__xxsubinterpreters.py
index 7baea69a4e5fa..81bce2e620421 100644
--- a/Lib/test/test__xxsubinterpreters.py
+++ b/Lib/test/test__xxsubinterpreters.py
@@ -39,6 +39,20 @@ def _run_output(interp, request, shared=None):
return rpipe.read()
+def _wait_for_interp_to_run(interp, timeout=None):
+ # bpo-37224: Running this test file in multiprocesses will fail randomly.
+ # The failure reason is that the thread can't acquire the cpu to
+ # run subinterpreter eariler than the main thread in multiprocess.
+ if timeout is None:
+ timeout = support.SHORT_TIMEOUT
+ start_time = time.monotonic()
+ deadline = start_time + timeout
+ while not interpreters.is_running(interp):
+ if time.monotonic() > deadline:
+ raise RuntimeError('interp is not running')
+ time.sleep(0.010)
+
+
@contextlib.contextmanager
def _running(interp):
r, w = os.pipe()
@@ -51,6 +65,7 @@ def run():
t = threading.Thread(target=run)
t.start()
+ _wait_for_interp_to_run(interp)
yield
More information about the Python-checkins
mailing list