-
-
Notifications
You must be signed in to change notification settings - Fork 30.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
_interpreters
is not thread safe on the free-threaded build
#126644
Comments
Confirmed on main. I'll try and deal with this today. |
index_pool.c: heap_pop
with interpreters and threads aborts free-threading buildindex_pool.c: heap_pop
with interpreters and threads aborts on free-threading build
There are two bugs here. First, the initial check for if the subinterpreter is running in The much more difficult issue is how we capture exceptions. Because we need to send the object to the caller, we have to detach from the subinterpreter, and then access it from the calling interpreter, which isn't thread safe, even on the GIL-ful build. The moment we detach from the thread state it's fair game for another thread to try and attach to it, and overwrite the exception that we want. There are a few possible fixes, and I'm not sure which one I want to do yet:
|
index_pool.c: heap_pop
with interpreters and threads aborts on free-threading build
OK, it looks like the exception-capturing problem is less severe than I thought. We only rely on the state of the interpreter for |
_interpreters
is not thread safe on the free-threaded build
Can you expand on this? Accessing Python objects from another interpreter is not safe in the free-threaded build, even with a lock. The GC and some other code paths assume that interpreter's and their objects are isolated. |
I was wrong with my analysis. I thought originally that we just moved the exception between the interpreter, but instead it gets stored and serialized. The issue right now is that The much bigger concern I have is that it seems |
Crash report
What happened?
First off, sorry for not being able to offer code that is more reduced and certain to trigger a repro.
The code below non-deterministically triggers
python: Python/index_pool.c:92: heap_pop: Assertion 'heap->size > 0' failed.
in a free-threading build withPYTHON_GIL=0
.Backtrace:
This code most usually results in one of the following errors, from most common to rarest:
Given that, running it multiple times seems necessary to trigger the correct abort in
heap_pop
. The affected code seems to have been included in #123926, so cc @mpage.Found using fusil by @vstinner.
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Output from running 'python -VV' on the command line:
Python 3.14.0a1+ experimental free-threading build (heads/main-dirty:54c63a32d0, Nov 8 2024, 20:16:36) [GCC 11.4.0]
Linked PRs
_interpreters
#126696The text was updated successfully, but these errors were encountered: