As long as I import class from my own library, my pickle failed, why? For example:
def fun():
print(1)
if __name__=="__main__":
import pickle
pickle.dump(fun, open('save', 'wb'))
The script above works fine, but if I add from xxx.yyy import zzz
(my class from my local library):
_pickle.PicklingError: Can't pickle <function fun at 0x7f5e40665e18>: attribute lookup fun on __main__ failed
occurs.
Why? Is there any workaround? By the way, the problem originally occurs when I was trying to use torch.multiprocessing
for distributed training, then I reduce the problem to above.