-
-
Notifications
You must be signed in to change notification settings - Fork 30.6k
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
PyThreadState_Next not thread safe #40857
Comments
I can't convince myself that PyThreadState_Next is If the GIL was held when the thread state was deleted, If these functions should work when the GIL is not |
Can someone take a look a this and either close or propose what to do? |
No reply to msg82072. |
This is actually true and it's quite easy to produce a bug that triggers a segmentation fault when iterating over a large list of threads create dynamically. That makes PyThreadState_Next barely usable for any program that has a few threads. The head mutex needs to be locked to be able to iterate safely over the list of thread. |
This issue is closed. Would you be able to write a reproducer script? If yes, maybe open a new issue, or I can reopen this one. |
It'd be great if you could reopen it. I'm interested in fixing it properly. It's impossible to "solve" in Python 2 since the head mutex is not accessible (it's static in pystate.c) but this is doable with Python 3 (yay). We'd simply need to provide a new API to lock/unlock the interpreter's mutex. How hard to you need the script to reproduce? I can try to spend some time to extract some of my code to have one if that's really needed (I'm using Cython to generate some of the C code). |
I reopened the issue and changed the version to 3.9. |
Are you talking about this lock? #define HEAD_LOCK(runtime) \
PyThread_acquire_lock((runtime)->interpreters.mutex, WAIT_LOCK)
#define HEAD_UNLOCK(runtime) \
PyThread_release_lock((runtime)->interpreters.mutex) |
Yes, that's the one 👍 |
Victor, do you have an idea of how you would like this mutex to be exposed? I see it only recently changed in Python 3.7 to be part of a structure, though this structure is not public AFAIU. Is adding 2 new lock/unlock C functions good enough? |
I'm not sure of what is the best approach. Currently, bpo-10915 is blocking different projects: "Make the PyGILState API compatible with multiple interpreters". We may have to fix this API first, and clarify the scope of the different locks. |
On Wed, Dec 11, 2019 at 7:02 AM STINNER Victor <report@bugs.python.org> wrote:
+1 |
See also bpo-35370: "Add _PyEval_SetTrace(tstate, func, arg) function". |
I marked bpo-26461 as a duplicate of this issue. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: