Skip to content

Deprecate and Then Remove PyGILState_GetThisThreadState() #131265

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

Open
ericsnowcurrently opened this issue Mar 14, 2025 · 0 comments
Open

Deprecate and Then Remove PyGILState_GetThisThreadState() #131265

ericsnowcurrently opened this issue Mar 14, 2025 · 0 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) topic-C-API type-feature A feature request or enhancement

Comments

@ericsnowcurrently
Copy link
Member

ericsnowcurrently commented Mar 14, 2025

Feature or enhancement

Proposal:

(See https://docs.python.org/3/c-api/init.html#c.PyGILState_GetThisThreadState.)

PyGILState_GetThisThreadState() was added as part of the PEP 311 implementation. However, it wasn't part of that proposal. It isn't clear that it was even meant to be public API.

If a user wants to know what the current thread state is then they should use PyThreadState_Get(). PyGILState_GetThisThreadState() is subtly different and surfaces some of the tricky PyGILState corner cases that PyThreadState_Get() blissfully ignores. A real issue here is that users are reasonably likely to stumble across PyGILState_GetThisThreadState() and, due to the name, use it instead of the proper API.

I can think of one thing that PyGILState_GetThisThreadState() does exclusively: it will tell you what existing thread state PyGILState_Ensure() will use, if any. It isn't clear to me if that's a meaningful use case.

Ultimately, I expect we would be fine to get rid of PyGILState_GetThisThreadState(). If still useful for core development, it could be moved to the internal C-API.

Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

No response

@ericsnowcurrently ericsnowcurrently added 3.14 bugs and security fixes topic-C-API type-feature A feature request or enhancement labels Mar 14, 2025
@picnixz picnixz added interpreter-core (Objects, Python, Grammar, and Parser dirs) and removed 3.14 bugs and security fixes labels Mar 14, 2025
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-C-API type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

2 participants