-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sys.setrecursionlimit no longer affecting pickle.dump #128590
Comments
With this program: import pickle
import sys
nested_object = current = {}
for i in range(100000):
next = {}
current['nested'] = next
current = next
for r in range(5000, 1000000, 5000):
try:
print("Trying with recursion limit", r)
sys.setrecursionlimit(r)
x = pickle.dumps(nested_object)
except RecursionError:
print("Recursion error") With Python 3.11, I get:
With 3.12, I get:
It is impossible to pickle an arbitrary long chain of dicts on any version of Python, there simply isn't enough C stack space. |
For your particular program, indeed. I'm not saying pickle dumping is perfect for all structures. And for the program I provided, the result is opposite of yours, and this is a regression. We've got a program in production that does pickle.dump, and without changing the program, it works fine from python 3.8 to python 3.11, yet it does not with python 3.12 and later with this exact message. This, by definition, is a regression. |
I'm categorizing this one as a pickle bug for now, although I'm not sure if it's directly related to pickle or if it's related to something else (maybe the recursion limit is reached before due to some other changes in the interpreter). |
But it was possible to pickle a chain of length 50000, and now it is not possible to pickle even a chain of length 5000. This is a regression. It is interesting that a chain of length 4990 can be pickled with arbitrary small recursion limit, but pickling a chain of length 5000 fails for any recursion limit. This is suspicious. I do not think that this issue is a pickle-specific. |
Bug report
Bug description:
This is a follow up of #112282 (updating doc).
It's also a different case of #128544 (import chains impacted).
In particular, on top of the doc no longer being correct for
sys.setrecursionlimit
, the regression needs to be fixed.Note: this works in python 3.11 or below.
Result of the run:
Impact: all programs trying to pickle data that is too nested cannot be ported to python 3.12 or 3.13 so far
CPython versions tested on:
3.12, 3.13
Operating systems tested on:
Linux, macOS, Windows
The text was updated successfully, but these errors were encountered: