[New-bugs-announce] [issue10987] Bizarre pickle -- exception interaction bug

Terry J. Reedy report at bugs.python.org
Sun Jan 23 07:06:10 CET 2011


New submission from Terry J. Reedy <tjreedy at udel.edu>:

Tool/scripts/find_recursionlimit.py includes test_cpickle() which, like the other test_xxx functions, is supposed to raise a RuntimeError when the recursion limit is reached. It appears to work correctly on 3.1 and I presume previously. On 3.2, test_cpickle() hangs. Here is much reduced code that shows the behavior:

import itertools
import io
import _pickle

# extracted from 'def test_cpickle' and condensed:
l = None
for n in itertools.count():
    try:
        raise KeyError
    except KeyError:
        for i in range(100):
            l = [l]
        print(n,i)
    _pickle.Pickler(io.BytesIO(), protocol=-1).dump(l)

The added print line prints 0,99 1,99, ... indefinitely. If the recursive list l is added to the print function, the attempt to create repr(l) raises a runtime error at n = 9. If we remove the try-except part:

l = None
for n in itertools.count():
    for i in range(100):
        l = [l]
    print(n,i)
    _pickle.Pickler(io.BytesIO(), protocol=-1).dump(l)

*pickle* now raises a RuntimeError, as expected in the original context, at n=4!

1. I do not actually know which behavior is buggy. I suppose the next step would be to capture and not toss the pickle output to see what is the difference.

2. At least for the present, I think the call to test_cpickle should be commented out in find_recursionlimit.py.

There seems to be other pickle and recursive structure issues, like #9269, but I did not see any the same as this.

----------
files: frl_pickle1.py
messages: 126874
nosy: belopolsky, pitrou, terry.reedy
priority: normal
severity: normal
status: open
title: Bizarre pickle -- exception interaction bug
type: behavior
versions: Python 3.2
Added file: http://bugs.python.org/file20489/frl_pickle1.py

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue10987>
_______________________________________


More information about the New-bugs-announce mailing list