[New-bugs-announce] [issue35943] PyImport_GetModule() can return partially-initialized module
Antoine Pitrou
report at bugs.python.org
Fri Feb 8 12:13:37 EST 2019
New submission from Antoine Pitrou <pitrou at free.fr>:
PyImport_GetModule() returns whatever is in sys.modules, even if the module is still importing and therefore only partially initialized.
One possibility is to reuse the optimization already done in PyImport_ImportModuleLevelObject():
/* Optimization: only call _bootstrap._lock_unlock_module() if
__spec__._initializing is true.
NOTE: because of this, initializing must be set *before*
stuffing the new module in sys.modules.
*/
spec = _PyObject_GetAttrId(mod, &PyId___spec__);
if (_PyModuleSpec_IsInitializing(spec)) {
PyObject *value = _PyObject_CallMethodIdObjArgs(interp->importlib,
&PyId__lock_unlock_module, abs_name,
NULL);
if (value == NULL) {
Py_DECREF(spec);
goto error;
}
Py_DECREF(value);
}
Py_XDECREF(spec);
Issue originally mentioned in issue34572.
----------
components: Interpreter Core
messages: 335097
nosy: brett.cannon, eric.snow, ncoghlan, pitrou
priority: normal
severity: normal
stage: needs patch
status: open
title: PyImport_GetModule() can return partially-initialized module
type: behavior
versions: Python 3.7, Python 3.8
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue35943>
_______________________________________
More information about the New-bugs-announce
mailing list