This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: cPickle doesn't raise error, pickle does (recursiondepth)
Type: Stage:
Components: Library (Lib) Versions:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: jhylton Nosy List: irmen, jhylton, loewis
Priority: normal Keywords:

Created on 2003-06-09 11:13 by irmen, last changed 2022-04-10 16:09 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
nopickle-recursion.py irmen, 2003-06-09 11:13 test script
Messages (6)
msg16290 - (view) Author: Irmen de Jong (irmen) (Python triager) Date: 2003-06-09 11:13
I have this object that causes a recursive call in the
__getattr__ method.

When I unpicke it using pickle, I get a runtimeerror
recursiondepth exceeded. When I unpickle it using
cPickle, everything appears to work -- no error is raised.
(tested on python 2.2.3 and 2.3b1)

The output of the attached python test file is:

***pickle***
Creating t...
Thing.__init__ name= myname
Pickle t...
Restore t...
FAIL!!!  <exceptions.RuntimeError instance at
0x00951C68> maximum recursion depth exceeded
***cPickle***
Creating t...
Thing.__init__ name= myname
Pickle t...
Restore t...
SUCCESS!!! name= myname
msg16291 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2003-06-14 14:23
Logged In: YES 
user_id=21627

This problem cannot be fixed. cPickle and pickle work
differently by nature; one is written in C, the other in
Python (as their names suggest).

You can try to sys.setrecursionlimit, to raise the nesting
level that pickle.py supports.
msg16292 - (view) Author: Irmen de Jong (irmen) (Python triager) Date: 2003-06-14 17:08
Logged In: YES 
user_id=129426

I fail to understand why this cannot be fixed. Is the
cPickle implementation that different from the pickle one?
In this particular case: it doesn't use __getattr__ the same
way as pickle does, apparently. 

Increasing sys.setrecursionlimit won't help because the
recursion is  infinite.
msg16293 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2003-06-14 19:19
Logged In: YES 
user_id=21627

I see. The problem occurs when trying to find __setstate__.
pickle.py uses getattr("setstate", None), which only masks
AttributeError, passing RuntimeError through. cPickle masks
all exceptions. It would be indeed possible to have one
match the other.

Reopening the report. Notice that there are dozens such
inconsistencies, so it will be a sisyphus job to fix them all.
msg16294 - (view) Author: Jeremy Hylton (jhylton) (Python triager) Date: 2003-06-16 16:53
Logged In: YES 
user_id=31392

cPickle has a load of PyErr_Clear() calls (well, 13) that
will mask bugs in user code.  I think it's worth fixing
them, but it is a non-trivial project.  I may take a crack
at it, but patches would help.
msg16295 - (view) Author: Jeremy Hylton (jhylton) (Python triager) Date: 2003-06-16 20:18
Logged In: YES 
user_id=31392

Fixed in rev 2.146 of cPickle.c.
It was easier than I thought.
History
Date User Action Args
2022-04-10 16:09:06adminsetgithub: 38614
2003-06-09 11:13:47irmencreate