Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32k
Add notes on nogil & reinitialization to the Opt-Out section in Module Isolation HOWTO#134141
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Doesn't free-threading perform a stop-the-world when importing modules?
A better question is: do we guarantee that it willalways stop the world? |
Uh oh!
There was an error while loading.Please reload this page.
colesbury commentedMay 17, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
We stop the world, temporarily enable the GIL, then resume (but with only one thread now holding the GIL), and the run the C extension initialization code. I think you might still need the locks in this example because of isolated sub interpreters each with their own GIL. We haven't explicitly guaranteed the stop the world behavior, but it'll probably be difficult to change in the future. |
Subinterpreters switch to the main interpreter to import an extension, so the GIL synchronizes it. |
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Well, that's something I'd like to change for 3.15 :) Let's play it safe and keep our options open? |
I'll yield, but I'm worried that it would break too much code to be feasible (or worth doing). I think all third-party extensions currently assume no other threads, right? Maybe we could make this opt-in. |
1f0a294
intopython:mainUh oh!
There was an error while loading.Please reload this page.
Thanks@encukou for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13. |
Thanks@encukou for the PR 🌮🎉.. I'm working now to backport this PR to: 3.14. |
…e Isolation HOWTO (pythonGH-134141)(cherry picked from commit1f0a294)Co-authored-by: Petr Viktorin <encukou@gmail.com>Co-authored-by: Sam Gross <colesbury@gmail.com>
…e Isolation HOWTO (pythonGH-134141)(cherry picked from commit1f0a294)Co-authored-by: Petr Viktorin <encukou@gmail.com>Co-authored-by: Sam Gross <colesbury@gmail.com>
GH-134491 is a backport of this pull request to the3.13 branch. |
GH-134492 is a backport of this pull request to the3.14 branch. |
Uh oh!
There was an error while loading.Please reload this page.
📚 Documentation preview 📚:https://cpython-previews--134141.org.readthedocs.build/