-
-
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
Allow C extensions to declare compatibility with free-threading #116322
Labels
interpreter-core
(Objects, Python, Grammar, and Parser dirs)
topic-free-threading
type-feature
A feature request or enhancement
Comments
swtaarrs
added
type-feature
A feature request or enhancement
interpreter-core
(Objects, Python, Grammar, and Parser dirs)
topic-free-threading
labels
Mar 4, 2024
This was referenced Mar 4, 2024
What warning category should this issue? |
This was referenced Mar 13, 2024
swtaarrs
changed the title
Implement
Allow C extensions to declare compatibility with free-threading
May 2, 2024
Py_mod_gil
slot for free-threading-safe extensions
colesbury
pushed a commit
that referenced
this issue
May 3, 2024
This PR adds the ability to enable the GIL if it was disabled at interpreter startup, and modifies the multi-phase module initialization path to enable the GIL when loading a module, unless that module's spec includes a slot indicating it can run safely without the GIL. PEP 703 called the constant for the slot `Py_mod_gil_not_used`; I went with `Py_MOD_GIL_NOT_USED` for consistency with gh-104148. A warning will be issued up to once per interpreter for the first GIL-using module that is loaded. If `-v` is given, a shorter message will be printed to stderr every time a GIL-using module is loaded (including the first one that issues a warning).
encukou
added a commit
to encukou/cpython
that referenced
this issue
May 6, 2024
encukou
added a commit
that referenced
this issue
May 6, 2024
colesbury
pushed a commit
that referenced
this issue
May 7, 2024
Add the ability to enable/disable the GIL at runtime, and use that in the C module loading code. We can't know before running a module init function if it supports free-threading, so the GIL is temporarily enabled before doing so. If the module declares support for running without the GIL, the GIL is later disabled. Otherwise, the GIL is permanently enabled, and will never be disabled again for the life of the current interpreter.
@swtaarrs is this finished now? |
Yep! |
SonicField
pushed a commit
to SonicField/cpython
that referenced
this issue
May 8, 2024
This PR adds the ability to enable the GIL if it was disabled at interpreter startup, and modifies the multi-phase module initialization path to enable the GIL when loading a module, unless that module's spec includes a slot indicating it can run safely without the GIL. PEP 703 called the constant for the slot `Py_mod_gil_not_used`; I went with `Py_MOD_GIL_NOT_USED` for consistency with pythongh-104148. A warning will be issued up to once per interpreter for the first GIL-using module that is loaded. If `-v` is given, a shorter message will be printed to stderr every time a GIL-using module is loaded (including the first one that issues a warning).
SonicField
pushed a commit
to SonicField/cpython
that referenced
this issue
May 8, 2024
SonicField
pushed a commit
to SonicField/cpython
that referenced
this issue
May 8, 2024
…thon#118560) Add the ability to enable/disable the GIL at runtime, and use that in the C module loading code. We can't know before running a module init function if it supports free-threading, so the GIL is temporarily enabled before doing so. If the module declares support for running without the GIL, the GIL is later disabled. Otherwise, the GIL is permanently enabled, and will never be disabled again for the life of the current interpreter.
colesbury
added a commit
to colesbury/cpython
that referenced
this issue
Jul 25, 2024
kumaraditya303
pushed a commit
that referenced
this issue
Jul 25, 2024
miss-islington
pushed a commit
to miss-islington/cpython
that referenced
this issue
Jul 25, 2024
(cherry picked from commit 9bb2e46) Co-authored-by: Serhiy Storchaka <[email protected]>
AlexWaygood
added a commit
to colesbury/cpython
that referenced
this issue
Jul 25, 2024
kumaraditya303
pushed a commit
that referenced
this issue
Jul 25, 2024
stefanholek
added a commit
to stefanholek/rl
that referenced
this issue
Oct 14, 2024
This means: "Do not re-enable the GIL when importing rl.readline." See python/cpython#116322 See python/cpython#116882
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
interpreter-core
(Objects, Python, Grammar, and Parser dirs)
topic-free-threading
type-feature
A feature request or enhancement
Feature or enhancement
There are a few pieces to this:
Py_mod_gil
slot, as described in PEP 703, that multi-phase init modules can use to indicate that they support free-threading.PyModule_ExperimentalSetGIL()
function (discussed here) that single-phase init modules can use in place ofPy_mod_gil
.1-3 are addressed in gh-116882; 4 will be addressed in a separate PR.
Linked PRs
The text was updated successfully, but these errors were encountered: