all Python 3sysfunction
sys.getrecursionlimit()
recursion
Return the interpreter's current maximum recursion depth (1000 by default); exceeding it raises RecursionError.
Syntax
sys.getrecursionlimit() -> int
The number counts frames on the whole interpreter stack, not just calls of your own function, so recursion started deep inside other calls hits RecursionError well before a thousand levels. It is a process-wide safety valve rather than a precise depth budget for your algorithm, and it says nothing about available memory.
Examples
import sys
print(sys.getrecursionlimit()) # → 1000
print(isinstance(sys.getrecursionlimit(), int)) # → True
sys.setrecursionlimit(2000)
print(sys.getrecursionlimit()) # → 2000
sys.setrecursionlimit(1000) # вернули значение по умолчанию
def deep(n): return deep(n + 1)
print(deep(0)) # → RecursionError
See also
Open in the full glossarydocs.python.orgReport an inaccuracy