Skip to content

Commit 94ade8c

Browse files
committed
Fix module load problem of cPickle in case of multithreading
1 parent a45fa39 commit 94ade8c

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix module load problem of cPickle in case of multithreading. Patch by
2+
Guoqiang Zhang.

Modules/cPickle.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3365,7 +3365,15 @@ find_class(PyObject *py_module_name, PyObject *py_global_name, PyObject *fc)
33653365
if (module == NULL)
33663366
return NULL;
33673367

3368+
_PyImport_AcquireLock();
33683369
module = PyDict_GetItem(module, py_module_name);
3370+
if (_PyImport_ReleaseLock() < 0) {
3371+
Py_XDECREF(module);
3372+
PyErr_SetString(PyExc_RuntimeError,
3373+
"not holding the import lock");
3374+
return NULL;
3375+
}
3376+
33693377
if (module == NULL) {
33703378
module = PyImport_Import(py_module_name);
33713379
if (!module)

0 commit comments

Comments
 (0)