diff --git a/Python/import.c b/Python/import.c index e44dc8c264d..2a4b5cc8732 100644 --- a/Python/import.c +++ b/Python/import.c @@ -182,6 +182,13 @@ PyImport_ExecCodeModule(name, co) if (v == NULL) return NULL; Py_DECREF(v); + + if ((m = PyDict_GetItemString(_PyImport_Modules, name)) == NULL) { + PyErr_SetString(PyExc_SystemError, + "loaded module not found in sys.modules"); + return NULL; + } + Py_INCREF(m); return m;