-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
Disallow calling PyDict_GetItem() with the GIL released #85016
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
Comments
For historical reasons, it was allowed to call the PyDict_GetItem() function with the GIL released. I propose to change PyDict_GetItem() to fail with a fatal error if it's called with the GIL released. To help C extension modules authors, I propose to keep a check at the runtime even in release build. Later, we may drop this check in release mode and only keep it in debug mode. In Python 3.8 and then 3.9, some functions started to crash when called without holding the GIL. It caused some bad surprises to C extension modules authors. Example: gdb developers with bpo-40826. In my opinion, holding the GIL was always required even if it is not very explicit in the documentation of the C API (only the documentation of few functions are explicit about the GIL). |
Current comment in Objects/dictobject.c:
PyDict_GetItem() is no longer called before Py_Initialize(). I reworked the Python startup to no longer use Python objects before Py_Initialize(): see PEP-587 (PyConfig).
Hum, since the whole test pass with the change and it was not documented that it was possible to call the function with the GIL released, I changed my mind and only kept the runtime check in debug mode. |
Note: I created this issue while working on bpo-40826 "PyOS_InterruptOccurred() now requires to hold the GIL: PyOS_Readline() crash". |
I made a similar change in _PyDict_GetItemHint(): commit d5fc998 (HEAD -> master, upstream/master)
|
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: