Skip to content

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

Closed
@ZeroIntensity

Description

@ZeroIntensity

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions