◐ Shell
reader mode source ↗
Skip to content

bpo-37224: Using threading.Event to make sure the thread is running already.#26598

Closed
shihai1991 wants to merge 1 commit into
python:mainfrom
shihai1991:bpo_37224
Closed

bpo-37224: Using threading.Event to make sure the thread is running already.#26598
shihai1991 wants to merge 1 commit into
python:mainfrom
shihai1991:bpo_37224

Conversation

@shihai1991

@shihai1991 shihai1991 commented Jun 8, 2021

Copy link
Copy Markdown
Member

@shihai1991

shihai1991 commented Jun 8, 2021

Copy link
Copy Markdown
Member Author

Hi, Victor, Eric. Would you mind to take a look this PR? @vstinner @ericsnowcurrently

I don't catch the error again by ./python -m test test__xxsubinterpreters -j250 -F -v over 11 hours in my local vm.

@shihai1991

Copy link
Copy Markdown
Member Author

In fact, there have two types of error:

  1. test_already_running: can't get the interp even it have been created in setup().
  2. test_still_running: interp isn't running immediately.

@ericsnowcurrently

Copy link
Copy Markdown
Member

@shihai1991, I'll take a look when I get a chance.

@shihai1991

shihai1991 commented Jun 10, 2021

Copy link
Copy Markdown
Member Author

@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

@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions Bot added the stale label Jul 16, 2021
@shihai1991

Copy link
Copy Markdown
Member Author

This PR hasn't fix the failed test cases, I updated the analysis conclusion in https://bugs.python.org/issue37224#msg397809.
And created a new PR in #27240 .

@shihai1991 shihai1991 closed this Jul 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review stale Stale PR or inactive for long period of time. tests Tests in the Lib/test dir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants