infinite recursion in pickle.load()

Thomas thomas.bugzilla at gmx.net
Wed Jul 1 08:38:36 EDT 2009


we regularly pickle and unpickle data from the same script (mostly 
dictionaries).

sometimes, a file written this way cannot be unpickled with 
pickle.load(), due to an infinite recursion with __getattr__ in 
codecs.py. here is a python2.5 stack trace excerpt:

/usr/local/lib/python2.5/pickle.py in load(file)
    1403
    1404 def load(file):
-> 1405     return Unpickler(file).load()
    1406
    1407 def loads(str):

/usr/local/lib/python2.5/pickle.py in load(self)
     891             while 1:
     892                 key = read(1)
--> 893                 dispatch[key](self)
     894         except _Stop, stopinst:
     895             return stopinst.value

/usr/local/lib/python2.5/pickle.py in load_build(self)
    1248         state = stack.pop()
    1249         inst = stack[-1]
-> 1250         setstate = getattr(inst, "__setstate__", None)
    1251         if setstate:
    1252             setstate(state)

/usr/local/lib/python2.5/codecs.py in __getattr__(self, name, getattr)
     328         """ Inherit all other methods from the underlying stream.
     329         """
--> 330         return getattr(self.stream, name)
     331
     332     def __enter__(self):

/usr/local/lib/python2.5/codecs.py in __getattr__(self, name, getattr)
     328         """ Inherit all other methods from the underlying stream.
     329         """
--> 330         return getattr(self.stream, name)
     331
     332     def __enter__(self):

     ...

The last frame repeats ad infinitum.

'inst' in the third frame is a <StreamWriter instance at 839b62c>

The problem is the same with cPickle.

This looks somewhat related to this Python issue, which is only about 
the exception reporting:
http://bugs.python.org/issue5508
(The title of the issue is the error you get when running our code in 
python2.6).

Any idea how to go about that?

T.



More information about the Python-list mailing list