Skip to content

Commit

Permalink
Add a test.
Browse files Browse the repository at this point in the history
  • Loading branch information
ericsnowcurrently committed May 5, 2023
1 parent 1c46317 commit 9cd8840
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
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 comments on commit 9cd8840

Please sign in to comment.