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

Change error message for a NULL thread state on the free-threaded build #127314

Closed
ZeroIntensity opened this issue Nov 27, 2024 · 0 comments
Closed
Labels

Comments

@ZeroIntensity
Copy link
Member

ZeroIntensity commented Nov 27, 2024

Feature or enhancement

Proposal:

In the C API, this message tends to be shown if you call a function without an active thread state:

the function must be called with the GIL held, after Python initialization and before Python finalization, but the GIL is released (the current Python thread state is NULL)

While reviewing #125962, I noticed that users don't really understand the distinction between having a thread state and the GIL being acquired, so I would imagine that C API users might end up very confused as to why Python is telling them that they need the GIL while it's disabled. In fact, I sort of noticed this in passing when figuring out #123134--users erroneously seemed to think that on the free-threaded build, it was OK to call functions in a fresh thread without calling PyGILState_Ensure or something first.

I think this is sort of a documentation problem (we should try to do a better job of clarifying the difference between "GIL" and "thread state"), but changing this error on the free-threaded build is a good start.

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Linked PRs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants