Skip to content

Conversation

tonybaloney
Copy link
Contributor

This is a very minor change, but in pystate there's a check that thread state shouldn't be null when releasing the GIL.

This is a very useful check. If someone accidentally calls release GIL and didn't acquire the GIL from a native thread in an embedded Python scenario, they get this helpful fatal error message because there is no thread state.

I noticed there is a TODO above this check speculating that it isn't required dating back to 2003.

It is required because it avoids a crash and null lookup.

This PR removes the comment.

@gmarkall
Copy link

If this check needs to be kept, does this mean that the following assert(holds_gil(tstate)); is redundant and could be removed too?

@tonybaloney
Copy link
Contributor Author

If this check needs to be kept, does this mean that the following assert(holds_gil(tstate)); is redundant and could be removed too?

That code is unreachable, so yes

@hauntsaninja hauntsaninja enabled auto-merge (squash) August 24, 2024 20:36
@hauntsaninja hauntsaninja merged commit 86f06cb into python:main Aug 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants