New submission from Crusader Ky <crusade...@gmail.com>:
As of CPython 3.8.0b1: 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. import _xxsubinterpreters as interpreters import pickle class C: pass c = C() interp_id = interpreters.create() c_bytes = pickle.dumps(c) interpreters.run_string( interp_id, "import pickle; pickle.loads(c_bytes)", shared={"c_bytes": c_bytes}, ) If the above is executed directly with the python command-line, it fails. If it's imported from another module, it works. One would expected behaviour compatible with sub-processes spawned with the spawn method, where the__main__ of the parent process is visible to the subprocess too. Workarounds: 1 - define everything that must be pickled in an imported module 2 - use CloudPickle ---------- messages: 345680 nosy: Crusader Ky, eric.snow priority: normal severity: normal status: open title: _xxsubinterpreters: Can't unpickle objects defined in __main__ type: behavior versions: Python 3.9 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue37292> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com