First post, recursive references with pickle.

George Sakkis george.sakkis at gmail.com
Mon Nov 10 22:36:15 CET 2008


On Nov 10, 2:23 pm, mark starnes <m.starne... at imperial.ac.uk> wrote:

> Hi everyone, this is my first post to this group, so please be gentle.
>
> I've written a class which, when I attempt to pickle, gives the error:
>
> *** RuntimeError: maximum recursion depth exceeded
>
> Is there a way to make pickle display data about what it's trying
> to do?  I'm thinking that if so, the recursive component will be
> immediately visible, easing the bug hunt.
>
> Any help would be appreciated.

How about commenting out one by one the attributes of the object
you're trying to pickle until you find the problematic one(s) ?
Something like:

class MyClass(object):
   ...
    def __getstate__(self):
        del self.foo
        return self.__dict__

Then do the same to the class of self.foo, and so on recursively,
until you find the real culprit.

HTH,
George



More information about the Python-list mailing list