-
-
Notifications
You must be signed in to change notification settings - Fork 31.5k
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
Fail PyGILState_Ensure() If Finalizing? #124622
Comments
A challenge in doing this is that |
I think a new GIL acquisition and release C API would be needed. The way the existing ones get used in existing C code is not amenible to suddenly bolting an error state onto; none of the existing C code is written that way. After the call they always just assume they have the GIL and can proceed. The API was designed as "it'll block and only return once it has the GIL" without any other option. |
This is something that seems fatal-error worthy rather than a new
That's been loosely discussed recently (in the context of subinterpreters, rather than the GIL), see #123728 (comment) |
If you don't mind, I will sort out the requirements under discussion and publish some issue in the near future. |
Tying threads together, a new |
I don't think it's a good idea to add new things with the term "GIL" in them. I'd prefer a totally new API design (e.g., |
Ok, I've been playing around with implementing this. I think we need to very clearly define two things:
|
Add new "OrFail" functions: * _PyEval_AcquireLockOrFail() * _PyEval_RestoreThreadOrFail() * _PyThreadState_AttachOrFail() * take_gil_or_fail()
Add new "OrFail" functions: * _PyEval_AcquireLockOrFail() * _PyEval_RestoreThreadOrFail() * _PyThreadState_AttachOrFail() * take_gil_or_fail()
I created #129688 to add |
PyThreadState_Ensure() and PyThreadState_Release() functions. Add new "OrFail" internal functions: * _PyEval_AcquireLockOrFail() * _PyEval_RestoreThreadOrFail() * _PyThreadState_AttachOrFail() * take_gil_or_fail()
Add PyThreadState_Ensure() and PyThreadState_Release() functions. Add new "OrFail" internal functions: * _PyEval_AcquireLockOrFail() * _PyEval_RestoreThreadOrFail() * _PyThreadState_AttachOrFail() * take_gil_or_fail()
See also comments on a previous similar attempt: #123728 |
Feature or enhancement
Proposal:
Once the runtime or current interpreter starts finalizing, we currently exit or stall the current thread as soon as it tries to acquire the GIL, via
PyThread_exit_thread()
(orPyThread_hang_thread()
after gh-105805). That includes inPyGILState_Ensure()
. However, in the case of the latter it might make more sense (i.e. friendlier) for the call to fail instead of exiting/hanging the current thread.FWIW, this is a hypothetical situation I noticed while looking at pystate.c. Also, the same scenario would be affected by gh-124619.
CC @gpshead
Has this already been discussed elsewhere?
No response given
Links to previous discussion of this feature:
No response
Linked PRs
The text was updated successfully, but these errors were encountered: