So I was trying to play with sys.getrecursionlimit()
and sys.setrecursionlimit()
methods.
By default recursion limit was 3000
.
I tried to check it using this code:
def recursive(n):
print(n)
recursive(n+1)
recursive(0)
It does print the numbers to 2979
, it delays for a second, prints 2980
and then raises the RecursionError
RecursionError: maximum recursion depth exceeded while calling a Python object
I know that error should be raised when it exceeds recursion limit that sys.getrecursionlimit()
returns, but it doesn't
Seems like it always doing it 20times before the recursion limit
I also tried this:
sys.setrecursionlimit(100)
def recursive(n):
print(n)
recursive(n+1)
recursive(0)
It still does the same thing, prints all the numbers to 79
, delays for a second, prints 80
and then raises the very same error
Why it does raise the error before it exceeds the real recursion limit that we set or get by sys.getrecursionlimit()
?