[issue34572] C unpickling bypasses import thread safety

Antoine Pitrou report at bugs.python.org
Fri Feb 8 12:09:57 EST 2019


Antoine Pitrou <pitrou at free.fr> added the comment:

I agree that more generally PyImport_GetModule() should be fixed.  But it should be done carefully so as to not to lose the performance benefit of doing it.  I think we should open a separate issue about that.

PS: 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);

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue34572>
_______________________________________


More information about the Python-bugs-list mailing list