python
runtime_error
official
true
RecursionError
ID: python/recursionerror
80%Fix Rate
95%Confidence
0Evidence
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.x | active | — | — | — |
Root Cause
The maximum recursion depth was exceeded. A recursive function has too many nested calls, usually due to a missing or broken base case.
genericOfficial Documentation
https://docs.python.org/3/library/exceptions.htmlWorkarounds
-
90% success Check that the recursive function has a proper base case that terminates
Add a condition that stops recursion (e.g., if n <= 1: return 1)
-
90% success Convert the recursive algorithm to an iterative one using a loop + explicit stack
Use while loop with a list as a manual stack
Dead Ends
Common approaches that don't work:
-
Increasing sys.setrecursionlimit() without fixing the algorithm
80% fail
May cause C stack overflow and process crash; does not fix infinite recursion