RecursionError
The Python exception raised when recursion goes deeper than the interpreter's limit, which is 1,000 frames by default.
In more detail
Python stops runaway recursion with this error rather than letting the process crash when the call stack overflows. sys.getrecursionlimit() shows the limit and sys.setrecursionlimit() changes it, but raising it only postpones the problem. The lasting fix is to rewrite the recursion as a loop.
Related terms
- call stack — The region of memory where a running program keeps one frame for each function call that has started but not yet returned.
- recursion — A technique where a function solves a problem by calling itself on a smaller version of the same problem.
- iteration — Repeating a block of steps in a loop, as opposed to having a function call itself.
- exception — An error object a program raises to stop normal flow and report that something went wrong.
Taught in
- Space, In-Place Work And The Call Stack — Algorithms & Data Structures for Working Engineers