You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
gh-116322 only works for modules using multi-phase init; we need an alternative mechanism for for single-phase init modules since they can't provide m_slots.
We originally considered indicating compatibility in the symbol table of the .so containing the module, either by the presence of a magic symbol, or by providing an alternate init function with a PyInitT_ prefix. As pointed out by @Yhg1s in Discord, that solution doesn't work with modules added to inittab.
Introduce a new public C API function PyModule_SetGIL(PyObject *mod, void *gil). If a single-phase init module can run without the GIL, it will call PyModule_SetGIL(mod, Py_MOD_GIL_NOT_USED) in its init function. This function will be a no-op in normal builds, and will set md_gil to its argument in free-threaded builds.
After the init function returns, if the module's md_gil member is set to Py_MOD_GIL_NOT_USED and the GIL was disabled before calling the init function, disable the GIL.
Feature or enhancement
Proposal:
gh-116322 only works for modules using multi-phase init; we need an alternative mechanism for for single-phase init modules since they can't provide
m_slots.We originally considered indicating compatibility in the symbol table of the
.socontaining the module, either by the presence of a magic symbol, or by providing an alternate init function with aPyInitT_prefix. As pointed out by @Yhg1s in Discord, that solution doesn't work with modules added to inittab.The current proposal is:
void *md_gilmember toPyModuleObject. It defaults toPy_MOD_GIL_USED(the same constant from Allow C extensions to declare compatibility with free-threading #116322).PyModule_SetGIL(PyObject *mod, void *gil). If a single-phase init module can run without the GIL, it will callPyModule_SetGIL(mod, Py_MOD_GIL_NOT_USED)in its init function. This function will be a no-op in normal builds, and will setmd_gilto its argument in free-threaded builds.md_gilmember is set toPy_MOD_GIL_NOT_USEDand the GIL was disabled before calling the init function, disable the GIL.