8000 gh-99113: Add a check for Py_MOD_PER_INTERPRETER_GIL_SUPPORTED by ericsnowcurrently · Pull Request #104206 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-99113: Add a check for Py_MOD_PER_INTERPRETER_GIL_SUPPORTED #104206

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Prev Previous commit
Next Next commit
Add a test.
  • Loading branch information
ericsnowcurrently committed May 5, 2023
commit 51d8587c0f1bcc05174341d4b8e03865936b904c
20 changes: 20 additions & 0 deletions Lib/test/test_import/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1861,6 +1861,26 @@ def test_multi_init_extension_non_isolated_compat(self):
with self.subTest(f'{modname}: not strict'):
self.check_compatible_here(modname, filename, strict=False)

@unittest.skipIf(_testmultiphase is None, "test requires _testmultiphase module")
def test_multi_init_extension_per_interpreter_gil_compat(self):
modname = '_test_shared_gil_only'
filename = _testmultiphase.__file__
loader = ExtensionFileLoader(modname, filename)
spec = importlib.util.spec_from_loader(modname, loader)
module = importlib.util.module_from_spec(spec)
loader.exec_module(module)
sys.modules[modname] = module

require_extension(module)
with self.subTest(f'{modname}: isolated, strict'):
self.check_incompatible_here(modname, filename, isolated=True)
with self.subTest(f'{modname}: not isolated, strict'):
self.check_compatible_here(modname, filename,
strict=True, isolated=False)
with self.subTest(f'{modname}: not isolated, not strict'):
self.check_compatible_here(modname, filename,
strict=False, isolated=False)

def test_python_compat(self):
module = 'threading'
require_pure_python(module)
Expand Down
19 changes: 18 additions & 1 deletion Modules/_testmultiphase.c
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,7 @@ PyInit__test_module_state_shared(void)
}


/* multiple interpreters supports */
/* multiple interpreters support */

static PyModuleDef_Slot non_isolated_slots[] = {
{Py_mod_exec, execfunc},
Expand All @@ -909,3 +909,20 @@ PyInit__test_non_isolated(void)
{
return PyModuleDef_Init(&non_isolated_def);
}


static PyModuleDef_Slot shared_gil_only_slots[] = {
{Py_mod_exec, execfunc},
{Py_mod_multiple_interpreters, Py_MOD_MULTIPLE_INTERPRETERS_SUPPORTED},
{0, NULL},
};

static PyModuleDef shared_gil_only_def = TEST_MODULE_DEF("_test_shared_gil_only",
shared_gil_only_slots,
testexport_methods);

PyMODINIT_FUNC
PyInit__test_shared_gil_only(void)
{
return PyModuleDef_Init(&shared_gil_only_def);
}
1 change: 0 additions & 1 deletion Objects/moduleobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,6 @@ PyModule_FromDefAndSpec2(PyModuleDef* def, PyObject *spec, int module_api_versio
goto error;
}
}
// XXX This case needs a test.
else if (multiple_interpreters != Py_MOD_PER_INTERPRETER_GIL_SUPPORTED
&& interp->ceval.own_gil
&& !_Py_IsMainInterpreter(interp)
Expand Down
0