diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2021-07-29 17:27:24 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-29 17:27:24 (GMT) |
commit | a438b37d9f4e571f139c990f6af65867b0c54a9a (patch) | |
tree | 0f1825fcc1f72c163f9f3b908e163716783e443c /Lib | |
parent | 86545bd94cc0ae05334a2d775257ee38937c420d (diff) | |
download | cpython-a438b37d9f4e571f139c990f6af65867b0c54a9a.zip cpython-a438b37d9f4e571f139c990f6af65867b0c54a9a.tar.gz cpython-a438b37d9f4e571f139c990f6af65867b0c54a9a.tar.bz2 |
To fix the random failed test cases of test___xxsubinterpreters in multiprocess. (GH-27240) (GH-27452)
(cherry picked from commit 9101b39e67c2437e88c0ad6b57aafd48ab08d431)
Co-authored-by: Hai Shi <shihai1992@gmail.com>
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test__xxsubinterpreters.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/Lib/test/test__xxsubinterpreters.py b/Lib/test/test__xxsubinterpreters.py index 7baea69..81bce2e 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 _running(interp): t = threading.Thread(target=run) t.start() + _wait_for_interp_to_run(interp) yield |