bpo-37224: Using threading.Event to make sure the thread is running already. by shihai1991 · Pull Request #26598 · python/cpython
@shihai1991, I'll take a look when I get a chance.
Ok. Thanks, Eric. Looks like I need to get to the bottom of this. I get this error again :(
test_already_running (test.test__xxsubinterpreters.RunStringTests) ... spam
[InterpreterID(0), InterpreterID(60)]
FAIL
======================================================================
FAIL: test_already_running (test.test__xxsubinterpreters.RunStringTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/shihai/cpython/Lib/test/test__xxsubinterpreters.py", line 836, in test_already_running
with self.assertRaises(RuntimeError):
AssertionError: RuntimeError not raised
----------------------------------------------------------------------
Ran 123 tests in 111.315s
FAILED (failures=1, skipped=6)
Warning -- Uncaught thread exception: RuntimeError
Exception in thread Thread-8 (run):
Traceback (most recent call last):
File "/home/shihai/cpython/Lib/threading.py", line 1006, in _bootstrap_inner
self.run()
File "/home/shihai/cpython/Lib/threading.py", line 943, in run
self._target(*self._args, **self._kwargs)
File "/home/shihai/cpython/Lib/test/test__xxsubinterpreters.py", line 50, in run
interpreters.run_string(interp, dedent(f"""
RuntimeError: unrecognized interpreter ID 60
test test__xxsubinterpreters failed
my second patch is:
diff --git a/Lib/test/test__xxsubinterpreters.py b/Lib/test/test__xxsubinterpreters.py index 7baea69a4e5..2b2a3d4bd7d 100644 --- a/Lib/test/test__xxsubinterpreters.py +++ b/Lib/test/test__xxsubinterpreters.py @@ -42,8 +42,13 @@ def _run_output(interp, request, shared=None): @contextlib.contextmanager def _running(interp): r, w = os.pipe() + # [bpo-37224](https://bugs.python.org/issue37224): Using threading.Event to make sure + # the interpreter is running already. + done = threading.Event() + print(interpreters.list_all()) def run(): interpreters.run_string(interp, dedent(f""" + {done.set()} # wait for "signal" with open({r}, encoding="utf-8") as rpipe: rpipe.read() @@ -51,6 +56,7 @@ def run(): t = threading.Thread(target=run) t.start() + done.wait() yield