]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
To fix the random failed test cases of test___xxsubinterpreters in multiprocess....
authorHai Shi <shihai1992@gmail.com>
Thu, 29 Jul 2021 17:05:49 +0000 (01:05 +0800)
committerGitHub <noreply@github.com>
Thu, 29 Jul 2021 17:05:49 +0000 (19:05 +0200)
Lib/test/test__xxsubinterpreters.py

index 7baea69a4e5fa72dcb20addb0f0aef7f35ac5150..81bce2e620421612a03bff2f795c00d61a46d612 100644 (file)
@@ -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