[issue44916] Random behaviour when importing two modules with the same name but different source files

Brett Cannon report at bugs.python.org
Mon Aug 16 12:35:41 EDT 2021


Brett Cannon <brett at python.org> added the comment:

So first, don't import from threads. It's non-deterministic as you have seen. You should do all imports **before** you start running multi-threaded code if multiple threads are going to access the 

Second, tossing in pickle is just asking for more trouble. 😉

The key thing to know is the master copy of a module is kept in `sys.modules`. But classes keep a reference to the module they were loaded from, not what `sys.modules` happens to have at that moment. So due to threading indeterminism it's quite possible to end up unpickling in such a way that the module that eventually ends up in `sys.modules` is not what your unpickled class is referencing.

As such, I'm closing as "wont fix".

----------
resolution:  -> wont fix
stage:  -> resolved
status: open -> closed

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


More information about the Python-bugs-list mailing list