diff --git a/Misc/NEWS.d/next/Library/2018-07-13-15-08-12.bpo-34110.0vn18S.rst b/Misc/NEWS.d/next/Library/2018-07-13-15-08-12.bpo-34110.0vn18S.rst new file mode 100644 index 00000000000000..9a38fbd5cd00c3 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2018-07-13-15-08-12.bpo-34110.0vn18S.rst @@ -0,0 +1,2 @@ +Fix module load problem of cPickle in case of multithreading. Patch by +Guoqiang Zhang. diff --git a/Modules/cPickle.c b/Modules/cPickle.c index 914ebb3eebeedf..729f8581b4aa77 100644 --- a/Modules/cPickle.c +++ b/Modules/cPickle.c @@ -3365,7 +3365,15 @@ find_class(PyObject *py_module_name, PyObject *py_global_name, PyObject *fc) if (module == NULL) return NULL; + _PyImport_AcquireLock(); module = PyDict_GetItem(module, py_module_name); + if (_PyImport_ReleaseLock() < 0) { + Py_XDECREF(module); + PyErr_SetString(PyExc_RuntimeError, + "not holding the import lock"); + return NULL; + } + if (module == NULL) { module = PyImport_Import(py_module_name); if (!module)