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?
picklegoes depth-first. Unfortunately I don't think there is a around this. TrycPicklebut it'll probably give the same error.picklegiven dummy data, you will see that it gos depth first. Since I guess that the format does not allow forward references, I'm afraid you won't be able to modify or create subclass of it in order to solve your problem...