Skip to content

Commit 51d8587

Browse files
Add a test.
1 parent e32c487 commit 51d8587

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

Lib/test/test_import/__init__.py

+20
Original file line numberDiff line numberDiff line change
@@ -1861,6 +1861,26 @@ def test_multi_init_extension_non_isolated_compat(self):
18611861
with self.subTest(f'{modname}: not strict'):
18621862
self.check_compatible_here(modname, filename, strict=False)
18631863

1864+
@unittest.skipIf(_testmultiphase is None, "test requires _testmultiphase module")
1865+
def test_multi_init_extension_per_interpreter_gil_compat(self):
1866+
modname = '_test_shared_gil_only'
1867+
filename = _testmultiphase.__file__
1868+
loader = ExtensionFileLoader(modname, filename)
1869+
spec = importlib.util.spec_from_loader(modname, loader)
1870+
module = importlib.util.module_from_spec(spec)
1871+
loader.exec_module(module)
1872+
sys.modules[modname] = module
1873+
1874+
require_extension(module)
1875+
with self.subTest(f'{modname}: isolated, strict'):
1876+
self.check_incompatible_here(modname, filename, isolated=True)
1877+
with self.subTest(f'{modname}: not isolated, strict'):
1878+
self.check_compatible_here(modname, filename,
1879+
strict=True, isolated=False)
1880+
with self.subTest(f'{modname}: not isolated, not strict'):
1881+
self.check_compatible_here(modname, filename,
1882+
strict=False, isolated=False)
1883+
18641884
def test_python_compat(self):
18651885
module = 'threading'
18661886
require_pure_python(module)

Modules/_testmultiphase.c

+18-1
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,7 @@ PyInit__test_module_state_shared(void)
892892
}
893893

894894

895-
/* multiple interpreters supports */
895+
/* multiple interpreters support */
896896

897897
static PyModuleDef_Slot non_isolated_slots[] = {
898898
{Py_mod_exec, execfunc},
@@ -909,3 +909,20 @@ PyInit__test_non_isolated(void)
909909
{
910910
return PyModuleDef_Init(&non_isolated_def);
911911
}
912+
913+
914+
static PyModuleDef_Slot shared_gil_only_slots[] = {
915+
{Py_mod_exec, execfunc},
916+
{Py_mod_multiple_interpreters, Py_MOD_MULTIPLE_INTERPRETERS_SUPPORTED},
917+
{0, NULL},
918+
};
919+
920+
static PyModuleDef shared_gil_only_def = TEST_MODULE_DEF("_test_shared_gil_only",
921+
shared_gil_only_slots,
922+
testexport_methods);
923+
924+
PyMODINIT_FUNC
925+
PyInit__test_shared_gil_only(void)
926+
{
927+
return PyModuleDef_Init(&shared_gil_only_def);
928+
}

Objects/moduleobject.c

-1
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,6 @@ PyModule_FromDefAndSpec2(PyModuleDef* def, PyObject *spec, int module_api_versio
323323
goto error;
324324
}
325325
}
326-
// XXX This case needs a test.
327326
else if (multiple_interpreters != Py_MOD_PER_INTERPRETER_GIL_SUPPORTED
328327
&& interp->ceval.own_gil
329328
&& !_Py_IsMainInterpreter(interp)

0 commit comments

Comments
 (0)