I have one question about sys.setrecursionlimit()
From the python docs this function:
Set the maximum depth of the Python interpreter stack to limit. This limit prevents infinite recursion from causing an overflow of the C stack and crashing Python.
The highest possible limit is platform-dependent. A user may need to set the limit higher when she has a program that requires deep recursion and a platform that supports a higher limit. This should be done with care because a too-high limit can lead to a crash.
Here is my question:
Let's take this useless recursive function:
def rec(N):
if N==0:
return 1
else:
return rec(N-1);
Now let's set the max recursion to 100:
sys.setrecursionlimit(100)
If I try rec(99)
(100 recursive calls), I get:
RuntimeError: maximum recursion depth exceeded
To calculate rec(99)
I need to set recursion limit to 105.
Why is this so?