Richard Oudkerk added the comment:

I think this change will potentially make the main module get imported twice 
under different names when we transfer pickled data between processes.  The 
current code (which is rather a mess) goes out of its way to avoid that.

Basically the main process makes sys.modules['__mp_main__'] an alias for the 
main module, and other process import the parent's main module with __name__ == 
'__mp_main__' and make sys.modules['__main__'] an alias for that.  This means 
that any functions/classes defined in the main module (from whatever process) 
will have

    obj.__module__ in {'__main__', '__mp_main__'}

Unpickling such an object will succeed in any process without reimporting the 
main module.

Attached is an alternative patch which is more like the original code and seems 
to work.  (Maybe modifying loader.name is an abuse of the API.)

----------
Added file: http://bugs.python.org/file29274/mp-importlib.diff

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue17314>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to