Question

I'm using the shelve module to add some persistence to my program. At first I was using the default bsddb in shelve but I had to change it to gdbm and after that change the exception occurs:

    Exception RuntimeError: 'maximum recursion depth exceeded in __subclasscheck__' in <type       'exceptions.AttributeError'> ignored

It seems to be raised (and caught) in the anydbm module by some whichdb call.

It does nothing bad, as the code finishes without problems, but it looks kinda bad. As far as I know I could use the warnings module to suppress the printing, however I would like to remove the exception completely.

I was looking through similar problems in other places (they occured in pylint, django and some other modules/packages) and everywhere it seems to be marked as "bug". Has anyone came up with solution for such behaviour in anydbm/shelve modules?

edit1. I found out that the thing causing this error is: def getattr(self, attr): return getattr(self.config, attr)

I'm trying to save into shelve a class which wraps another class - that's why the getattr function is overridden. Is there a way to write it and not get infinite loop?

Was it helpful?

Solution

Alright, I think I managed to fix the issue. The problem was the wrapper class didn't have setstate and getstate functions. So far it seems to work. The wrapped class doesn't need the setstate and getstate.

I used simple getstate and setstate functions for the wrapper class:

    def __getstate__(self):
        '''
        Getstate for pickle (used by shelve module)
        '''
        return self.__dict__

    def __setstate__(self, dictionary):
        '''
        Setstate for pickle (used by shelve module)
        '''
        self.__dict__ = dictionary
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top