mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
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:
parent
60bd111844
commit
853163d3b5
9 changed files with 352 additions and 32 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue