I've made a small function that will actually measure the max recursion limit:
r = x
r = f(x+1)
except Exception as e:
In : import sys
In : sys.getrecursionlimit()
In : f(0)
maximum recursion depth exceeded
The recursion limit is not the limit on recursion but the maximum depth of the python interpreter stack.There is something on the stack before your function gets executed. Spyder executes some python stuff before it calls your script, as do other interpreters like ipython.
You can inspect the stack via methods in the
In CPython for me:
In Ipython for me:
As knbk pointed out in the comments as soon as you hit the stack limit a RecursionError is thrown and the interpreter raises the stack limit a bit to give you a possibility to handle the error gracefully. If you also exhaust that limit python will crash.