gh-116322: Enable the GIL while loading C extension modules (#118560)

Add the ability to enable/disable the GIL at runtime, and use that in
the C module loading code.

We can't know before running a module init function if it supports
free-threading, so the GIL is temporarily enabled before doing so. If
the module declares support for running without the GIL, the GIL is
later disabled. Otherwise, the GIL is permanently enabled, and will
never be disabled again for the life of the current interpreter.
This commit is contained in:
Brett Simmers 2024-05-06 20:07:23 -07:00 committed by GitHub
parent 60bd111844
commit 853163d3b5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 352 additions and 32 deletions

View file

@ -2433,8 +2433,7 @@ sys__is_gil_enabled_impl(PyObject *module)
/*[clinic end generated code: output=57732cf53f5b9120 input=7e9c47f15a00e809]*/
{
#ifdef Py_GIL_DISABLED
PyInterpreterState *interp = _PyInterpreterState_GET();
return interp->ceval.gil->enabled;
return _PyEval_IsGILEnabled(_PyThreadState_GET());
#else
return 1;
#endif