This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Sagiv.Malihi
Recipients Sagiv.Malihi
Date 2011-08-02.08:48:34
SpamBayes Score 8.705978e-10
Marked as misclassified No
Message-id <1312274915.97.0.144720506946.issue12680@psf.upfronthosting.co.za>
In-reply-to
Content
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).
History
Date User Action Args
2011-08-02 08:48:36Sagiv.Malihisetrecipients: + Sagiv.Malihi
2011-08-02 08:48:35Sagiv.Malihisetmessageid: <1312274915.97.0.144720506946.issue12680@psf.upfronthosting.co.za>
2011-08-02 08:48:35Sagiv.Malihilinkissue12680 messages
2011-08-02 08:48:34Sagiv.Malihicreate