[issue12680] cPickle.loads is not thread safe due to non-thread-safe imports
Sagiv Malihi
report at bugs.python.org
Tue Aug 2 10:48:35 CEST 2011
Sagiv Malihi <sagivmalihi at gmail.com> added the comment:
OK, digging deeper reveals that there are actually two bugs here, one is conceptual in the python importing mechanism, and the other is technical in cPickle.
The first bug:
PyImport_ExecCodeModuleEx adds the module to sys.modules *before* actually executing the code. This is a design flaw (can it really be changed? )
Demonstrating this bug is easy using the foo.py module from the previous comment:
def f():
if 'bla' in sys.modules:
bla = sys.modules['bla']
else:
import bla
return bla.A()
running two instances of f in two threads results in the same error.
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).
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue12680>
_______________________________________
More information about the Python-bugs-list
mailing list