You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Every recursive call of Python function increases the recursion_depth counter. Some recursive calls of C functions also increase it. A RecursionError is raised when it exceed the limit (sys.getrecursionlimit()).
The following code expectedly prints a value close to 1/2 of sys.getrecursionlimit() in all Python versions before 3.7 (including 2.7):
One for every test() function call and one for every generator expression. Both are shown in a traceback.
In Python 3.7 to 3.11 it prints 1/3 of the limit. Perhaps it adds one level for every list.extend() call?
In Python 3.12 it returns to 1/2 of the limit.
But in the main branch it only prints 1/6 of the limit. How can it increase the recursion_depth counter 6 times per the recursion level? It is a regression, because now the code that was successfully passed in previous versions starts to raise a RecursionError. See #111803 for example.
It prints the whole limit in Python before 3.7, 1/2 of the limit in Python 3.7 to 3.12 (no difference between 3.11 and 3.12!), and only 1/6 of the limit in the main branch.
On installed 3.13.0a3, (tags/v3.13.0a3:f009305, Jan 17 2024, 13:25:20), I get 513: IDLE, Win10, rc=1000. With debug no-gil build, (heads/main-dirty:b04c5005cc, Jan 21 2024, 02:00:08), I get 165 (rc same). Recompile plain build.bat, 513 again. Recompile with -d, back to 165.
Under a debug build of WASI w/ a modification to print before calling list(test(i)), I got to 58 on main and then the call stack was exhausted (i.e. the WASI host killed the run before RecursionError was reached). A non-debug build gets to 167 and doesn't crash. 3.12 non-debug is 165. For a non-debug build of 3.11 it's 198.
Activity
serhiy-storchaka commentedon Jan 22, 2024
Other example that involves only one Python (generator) function call per recursion level:
It prints the whole limit in Python before 3.7, 1/2 of the limit in Python 3.7 to 3.12 (no difference between 3.11 and 3.12!), and only 1/6 of the limit in the main branch.
terryjreedy commentedon Jan 22, 2024
On installed 3.13.0a3, (tags/v3.13.0a3:f009305, Jan 17 2024, 13:25:20), I get 513: IDLE, Win10, rc=1000. With debug no-gil build, (heads/main-dirty:b04c5005cc, Jan 21 2024, 02:00:08), I get 165 (rc same). Recompile plain build.bat, 513 again. Recompile with -d, back to 165.
brettcannon commentedon Jan 22, 2024
Under a debug build of WASI w/ a modification to print before calling
list(test(i)), I got to 58 onmainand then the call stack was exhausted (i.e. the WASI host killed the run beforeRecursionErrorwas reached). A non-debug build gets to 167 and doesn't crash. 3.12 non-debug is 165. For a non-debug build of 3.11 it's 198.GH-114456: lower the recursion limit under WASI for debug builds (GH-…
pythonGH-114456: lower the recursion limit under WASI for debug builds (
pythonGH-114456: lower the recursion limit under WASI for debug builds (