mirror of
https://github.com/python/cpython.git
synced 2025-10-05 06:31:48 +00:00
[3.6] bpo-30814: Fixed a race condition when import a submodule from a package. (GH-2580). (#2598)
(cherry picked from commit b4baacee1a
)
This commit is contained in:
parent
aaa4f99151
commit
03b0e8374b
7 changed files with 340 additions and 325 deletions
|
@ -1533,18 +1533,7 @@ PyImport_ImportModuleLevelObject(PyObject *name, PyObject *globals,
|
|||
}
|
||||
|
||||
mod = PyDict_GetItem(interp->modules, abs_name);
|
||||
if (mod == Py_None) {
|
||||
PyObject *msg = PyUnicode_FromFormat("import of %R halted; "
|
||||
"None in sys.modules", abs_name);
|
||||
if (msg != NULL) {
|
||||
PyErr_SetImportErrorSubclass(PyExc_ModuleNotFoundError, msg,
|
||||
abs_name, NULL);
|
||||
Py_DECREF(msg);
|
||||
}
|
||||
mod = NULL;
|
||||
goto error;
|
||||
}
|
||||
else if (mod != NULL) {
|
||||
if (mod != NULL && mod != Py_None) {
|
||||
_Py_IDENTIFIER(__spec__);
|
||||
_Py_IDENTIFIER(_initializing);
|
||||
_Py_IDENTIFIER(_lock_unlock_module);
|
||||
|
@ -1585,10 +1574,6 @@ PyImport_ImportModuleLevelObject(PyObject *name, PyObject *globals,
|
|||
}
|
||||
}
|
||||
else {
|
||||
#ifdef WITH_THREAD
|
||||
_PyImport_AcquireLock();
|
||||
#endif
|
||||
/* _bootstrap._find_and_load() releases the import lock */
|
||||
mod = _PyObject_CallMethodIdObjArgs(interp->importlib,
|
||||
&PyId__find_and_load, abs_name,
|
||||
interp->import_func, NULL);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue