-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
Open
Labels
3.13bugs and security fixesbugs and security fixes3.14bugs and security fixesbugs and security fixes3.15new features, bugs and security fixesnew features, bugs and security fixestopic-C-APItopic-free-threadingtopic-subinterpreterstriagedThe issue has been accepted as valid by a triager.The issue has been accepted as valid by a triager.
Description
In the C API, we have some functions that need to access state that is deleted by finalization. For example, PyGILState_Ensure
accesses the gilstate, and that can be concurrently deallocated. In that specific case, I proposed #132510 as a fix, but really, we should have a better way to protect state against a finalizing interpreter. I'm not sure whether to categorize this as a bug or a feature.
I think the best way to do this is through a finalizing counter similar to how PEP-788 proposes preventing interpreter shutdown. So, for functions that don't require an attached thread state, we need something like:
int
PySomething_Whatever(PyInterpreterState *interp)
{
if (_PyInterpreterState_CriticalSection(interp) < 0) {
// Interpreter has finalized
return -1;
}
/* Do critical operation */
_PyInterpreterState_EndCriticalSection(interp);
return 0;
}
Does this approach seem reasonable to everyone?
Metadata
Metadata
Assignees
Labels
3.13bugs and security fixesbugs and security fixes3.14bugs and security fixesbugs and security fixes3.15new features, bugs and security fixesnew features, bugs and security fixestopic-C-APItopic-free-threadingtopic-subinterpreterstriagedThe issue has been accepted as valid by a triager.The issue has been accepted as valid by a triager.
Projects
Status
Todo