-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
sys.setrecursionlimit docs are incorrect in 3.12 and 3.13 #112282
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
Comments
I confirm this breaks some code out there. In particular, we are unable to move from python 3.11 to anything higher, since we can no longer |
+1 to updating the docs. The text from What's New in Python 3.12 might be a good starting point. I think it would also be worth documenting that the recursion limit can also be triggered by long import chains, as described in this issue. Do people agree, and if so does it make sense to fold that issue into this one? |
same issue |
I have same issue with my 3.12 python import sys
sys.setrecursionlimit(1000000)
from functools import cache
@cache
def f(n):
if n >= 2025:
return 1
return n - f(n + 2) - f(n + 4)
print(f(20) + f(25))
Tried with python 3.11 and 3.8 and everything works |
…ion_remaining Both were added in 3.13, are undocumented, and don't make sense in 3.14 due to changes in the stack overflow detection machinery (pythongh-112282).
…maining (GH-133080) Both were added in 3.13, are undocumented, and don't make sense in 3.14 due to changes in the stack overflow detection machinery (gh-112282). PEP 387 exception for skipping a deprecation period: python/steering-council#288
Since 3.12,
sys.setrecursionlimit
does not control the recursion limit of the C stack (it's hardcoded inPy_C_RECURSION_LIMIT
, due to #91079), while the 3.13 docs sayThe fallout can be seen in #112215 (basically, any code that uses
lru_cache
in combination withsys.setrecursionlimit
is potentially, or actually, broken in 3.12, while still working in 3.11) or in #107263 (which was papered over with an increase ofPy_C_RECURSION_LIMIT
, not really fixed).This is an obvious change of behaviour, as code working in 3.11 can easily be broken in 3.12, as found in #112215
Such changes should carry a warning in the documentation.
Potentially, any recursive Python code combining C recursion (in a module, e.g.
lru_cache
, via@lru_cache
decorator) with increased (beyond the hardcodedPy_C_RECURSION_LIMIT
)sys.setrecursionlimit
is bound to be broken in 3.12.I believe the whole hardcoding of
Py_C_RECURSION_LIMIT
has to be fixed (perhaps with a separate API provided to change it), as it's a regression and an incompatible change of code behaviour, but meanwhile the docs have to reflect the reality.The text was updated successfully, but these errors were encountered: