> PyImport_ExecCodeModuleEx adds the module to sys.modules *before*
> actually executing the code. This is a design flaw (can it really be
> changed? )
I guess it is done so to allow for circular imports.
> The second bug: in cPickle.c: func_class()
> cPickle 'manually' checks if a module is in sys.modules instead of
> letting the import mechanism do it for him (hence breaking the import
> lock's defense here).
I would guess it is an optimization shortcut. A solution (while keeping the optimization) would be to take the import lock before checking sys.modules.
Note that the _pickle module in 3.x has the same kind of logic, and therefore probably the same issue too (haven't tested). |