Skip to content

Commit fc68878

Browse files
committed
Set the Py_MOD_GIL_NOT_USED flag on modules.
This indicates that the free-threaded build of Python can keep the GIL disabled when the module is loaded. Without this module flag, importing the module will cause the GIL to be re-enabled. A warning is emitted if this happens.
1 parent cfbefe8 commit fc68878

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/module.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,14 @@ BOOST_PYTHON_DECL void scope_setattr_doc(char const* name, object const& x, char
4040

4141
BOOST_PYTHON_DECL PyObject* init_module(PyModuleDef& moduledef, void(*init_function)())
4242
{
43+
PyObject *mod = PyModule_Create(&moduledef);
44+
#ifdef Py_GIL_DISABLED
45+
if (mod != NULL) {
46+
PyUnstable_Module_SetGIL(mod, Py_MOD_GIL_NOT_USED);
47+
}
48+
#endif
4349
return init_module_in_scope(
44-
PyModule_Create(&moduledef),
50+
mod,
4551
init_function);
4652
}
4753

0 commit comments

Comments
 (0)