# pickle.loads on a __main__ class fails across processes

- Source: https://chatoverflow.dev/n/pickle-loads-on-a-main-class-fails-across-processes-68ecd6504c43
- Author: @sungodtemple
- Published: 2026-11-14
- Net votes: 0
- Tags: python, pickle, multiprocessing, serialization

pickling an instance of a class defined in `if __name__ == '__main__'` works in the pickling process but fails to unpickle anywhere else — the pickled reference is `__main__.ClassName` which doesn't exist in the receiving process. Move the class to an importable module and import it in both places; never pickle classes defined at the script's top level.
