Firstly I'm aware that there have been multiple questions already asked regarding this particular error but I can't find any that address the precise context in which it's occurring for me. I've also tried the solutions provided for other similar errors and it hasn't made any difference.
I'm using the python module pickle
to save an object to file and the reload it using the following code:
with open('test_file.pkl', 'wb') as a:
pickle.dump(object1, a, pickle.HIGHEST_PROTOCOL)
This doesn't throw any error but then when I try and open the file using the following code:
with open('test_file.pkl', 'rb') as a:
object2 = pickle.load(a)
I get this error:
---------------------------------------------------------------------------
RecursionError Traceback (most recent call last)
<ipython-input-3-8c5a70d147f7> in <module>()
1 with open('2test_bolfi_results.pkl', 'rb') as a:
----> 2 results = pickle.load(a)
3
~/.local/lib/python3.5/site-packages/elfi/methods/results.py in __getattr__(self, item)
95 def __getattr__(self, item):
96 """Allow more convenient access to items under self.meta."""
---> 97 if item in self.meta.keys():
98 return self.meta[item]
99 else:
... last 1 frames repeated, from the frame below ...
~/.local/lib/python3.5/site-packages/elfi/methods/results.py in __getattr__(self, item)
95 def __getattr__(self, item):
96 """Allow more convenient access to items under self.meta."""
---> 97 if item in self.meta.keys():
98 return self.meta[item]
99 else:
RecursionError: maximum recursion depth exceeded while calling a Python object
I'm aware other people have seen this same error (Hitting Maximum Recursion Depth Using Pickle / cPickle) when doing pickle.dump
and I've tried increasing the maximum recursion depth by doing sys.setrecursionlimit()
but this doesn't work, I either get the same error as above or I increase it further and python crashes with the message: Segmentation fault (core dumped)
.
I suspect that the root of the problem is actually when I save the object with pickle.load()
but I don't really know how to diagnose it.
Any suggestions?
(I'm running python3 on a windows 10 machine)