Skip to content
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

gh-127989: C API: Refer to attached thread states instead of the GIL #127990

Merged
merged 76 commits into from
Mar 20, 2025

Conversation

ZeroIntensity
Copy link
Member

@ZeroIntensity ZeroIntensity commented Dec 16, 2024

As I said in the issue, this is a big change, but it should help clear things up for users. Any feedback, or pointing out flaws, is definitely appreciated!


📚 Documentation preview 📚: https://cpython-previews--127990.org.readthedocs.build/

@ncoghlan
Copy link
Contributor

Ping @ericsnowcurrently (I don't think this is urgent enough to override another core dev's "changes requested" flag, but I also don't agree with all of Eric's suggested changes, so we need clarification of which comments were the ones specifically intended to be merge blocking)

@ZeroIntensity
Copy link
Member Author

Ok, I've come up with a compromise here. There seems to be quite a bit of opposition to calling this a "runtime context," so I've kept the phrase "thread state," but I've changed the glossary definitions to mostly fit Eric's suggestions. At the bottom of the "attached thread state" definition, I've added a note about free-threading:

In free-threaded builds of Python, threads can concurrently hold an attached thread state, allowing for true parallelism of the bytecode interpreter.

I think this is an important part to emphasize--from the user's perspective, all free-threading really does is allow for multiple active thread states at a time, and that gives a good intuitive sense of why things like PyGILState_Ensure are still needed on FT builds. If there's any other places we should try to mention this, let me know.

Regarding this part:

current does not imply attached, but attached does implies current

I decided just to drop any mention of the "current thread-local state pointer" and just replaced everything with being either "attached" or not. It's probably better to keep how we expose thread states out of the documentation.

So, with all that in mind: I didn't expect the Spanish Inquisition

@bedevere-app
Copy link

bedevere-app bot commented Feb 12, 2025

Nobody expects the Spanish Inquisition!

@ericsnowcurrently: please review the changes made to this pull request.

Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I'm fine with "attached thread state" and "active thread state".

Copy link
Member

@encukou encukou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM; I'll merge ~tomorrow if there are no objections.

IMO, it's fine to have C API details in the glossary for terms related to the C API -- which these are.

My main worry is that per the SC's pronouncement on PEP 703, all changes related to free-threading should be revertable. Unfortunately, we can't really put #ifs in the docs, so the revert will need to start with a manual search for "free-threading".
But, I expect the term "attached thread state" -- and so, the bulk of the changes here -- to stay even if nogil needs to be abandoned for some reason.

@encukou
Copy link
Member

encukou commented Mar 19, 2025

Oh, I missed the change request (is it just me or were these more prominent not that long ago?)

@ericsnowcurrently, do you want to block this iteration?

@ericsnowcurrently
Copy link
Member

No real objections; I defer to you, Victor and Alyssa.

@vstinner
Copy link
Member

vstinner commented Mar 20, 2025

I already approved the PR :-)

@encukou
Copy link
Member

encukou commented Mar 20, 2025

Thanks! Let's build on this :)

@encukou encukou merged commit 86d5fa9 into python:main Mar 20, 2025
24 checks passed
@ZeroIntensity ZeroIntensity deleted the clarify-gil-tstate branch March 20, 2025 12:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir skip news
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

7 participants