mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
To fix the random failed test cases of test___xxsubinterpreters in multiprocess. (GH-27240)
This commit is contained in:
parent
ccefa8a905
commit
9101b39e67
1 changed files with 15 additions and 0 deletions
|
@ -39,6 +39,20 @@ def _run_output(interp, request, shared=None):
|
||||||
return rpipe.read()
|
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
|
@contextlib.contextmanager
|
||||||
def _running(interp):
|
def _running(interp):
|
||||||
r, w = os.pipe()
|
r, w = os.pipe()
|
||||||
|
@ -51,6 +65,7 @@ def _running(interp):
|
||||||
|
|
||||||
t = threading.Thread(target=run)
|
t = threading.Thread(target=run)
|
||||||
t.start()
|
t.start()
|
||||||
|
_wait_for_interp_to_run(interp)
|
||||||
|
|
||||||
yield
|
yield
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue