-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't unpickle objects defined in __main__ #46
Comments
This definitely sounds like a bug. :( Thanks for finding that! Please open a new issue on bugs.python.org and feel free to nosy me. |
I'm going to track this here along with other subinterpreter-related bugs that need short-term attention. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
(https://bugs.python.org/issue37292)
ORIGINAL POST:
As of CPython 3.8.0b1, main branch (please let me know if there's a different branch I should use):
If one pickles an object that is defined in the
__main__
module, sends it to a subinterpreter as bytes, and then tries unpickling it there, it fails saying that__main__
doesn't define it.If the above is executed directly with the python command-line, it fails.
If it's imported from another module, it works.
I'm unsure if that's working as intended or not; I was expecting behaviour compatible with sub-processes spawned with the
spawn
method, where the__main__
of the parent process is visilble to the subprocess too.Workarounds:
1 - define everything that must be pickled in an imported module
2 - use cloudPickle, which implements a hardcoded special case that makes it pickle the whole code of any object defined in
__main__
.Possible future solutions:
__main__
in a subinterpreter__main__
in a subinterpreter__module__
for all objects in__main__
__main__
as a named module (insys.modules
)__module__
for all objectsThe text was updated successfully, but these errors were encountered: