I'm running python3.7.9-64bit installed by anaconda on Mac.
Just happens to meet three problems.
(Though I write fix_import=False, changing this does not make any difference)
1st Problem, if two dicts with the same key got pickled in one file, loading the 2nd dict will raise KeyError.
import pickle
d1={"a":1}# if two dicts has the same key
d2={"a":0}# does not matter what value is stored.
tmpf=open("deleteThis","wb")
pkl=pickle.Pickler(tmpf,protocol=4,fix_imports=False)
pkl.dump(d1)
pkl.dump(d2)
tmpf.close()
tmpf2=open("deleteThis","rb")
td1=pickle.load(tmpf2)
td2=pickle.load(tmpf2)# KeyError 1
2nd Problem, though it probably relates to the first one, if the 2nd dict has a dict D inside it which share the same key with the 1st dict, then D's key changes when loaded.
d1={"a":1}
d2={"lll":{"a":2} }# this "a" will always be "lll"
tmpf=open("deleteThis","wb")
pkl=pickle.Pickler(tmpf,protocol=4,fix_imports=True)
pkl.dump(d1)
pkl.dump(d2)
tmpf.close()
tmpf2=open("deleteThis","rb")
td1=pickle.load(tmpf2)
td2=pickle.load(tmpf2)
print(td1,td2)# {'a': 1} {'lll': {'lll': 2}}
3rd Problem, and the most devastating to me, if there is a dict get pickle.dump and the 2nd dumped dict has a list of dicts sharing the same key, loading the 2nd dict raise KeyError.
d1={"b":0}
d2={ "l":[{"a":2} , {"a",3}] }
tmpf=open("deleteThis","wb")
pkl=pickle.Pickler(tmpf,protocol=4,fix_imports=True)
pkl.dump(d1)
pkl.dump(d2)
tmpf.close()
tmpf2=open("deleteThis","rb")
td1=pickle.load(tmpf2)
td2=pickle.load(tmpf2)# KeyError
These problems only happens with pickle( protocol=4 ).
Nothing goes wrong with protocol=3
Unknown about python>3.8 or protocl=5