I'm trying to pickle instance of my cellular automata class, but I get this error:
RuntimeError: maximum recursion depth exceeded while calling a Python object
My cellular automata consist from list of cells (and bunch of other things) where each cell has pointer to it's neighbours. In this particular CA, there is 256 cells. Now, I know that pickler should be able to recognise already pickled objects.
From docs:
*The pickle module keeps track of the objects it has already serialized, so that later references to the same object won’t be serialized again.
So I don't really know, why I exceeding max recursion depth.
I think that maybe pickler does depth-first pickling, so that it first follow pointers, exceed recursion stack and then raise exception. I know I can extend maximum recursion depth with sys.setrecursionlimit()
, but I don't consider that good nor scalable solution.
First question: Does pickler depth-first pickling?
Second question: Any idea how to prevent this exception?