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()
t = threading.Thread(target=run)
t.start()
+ _wait_for_interp_to_run(interp)
yield