[issue19702] Update pickle to PEP 451

Nick Coghlan report at bugs.python.org
Tue Dec 17 13:40:56 CET 2013


Nick Coghlan added the comment:

Issue 19700 means that runpy now ensures that __main__.__spec__ is set appropriately when __main__ is executed via the import system.

Issue 19946 means that multiprocessing now ensures that __main__ is configured correctly in child processes to reference a properly initialised "fake main" to allow pickle compatibility with classes and functions defined in __main__ outside "if __name__ == '__main__'" guards.

The proposal here is that we make the following changes:

- runpy will ensure that when __main__ is executed via the import system, it will also be aliased in sys.modules as __spec__.name
- if __main__.__spec__ is set, pickle will use __spec__.name rather than __name__ to pickle classes, functions and methods defined in __main__
- multiprocessing is updated appropriately to skip creating __mp_main__ in child processes when __main__.__spec__ is set in the parent process

While I still think this is a reasonable idea, I think it qualifies as a new feature, and hence is better postponed to Python 3.5

----------
dependencies: +Handle a non-importable __main__ in multiprocessing
nosy: +larry
versions: +Python 3.5 -Python 3.4

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue19702>
_______________________________________


More information about the Python-bugs-list mailing list