Recursion occurs when a function calls itself (see Section 7.4: Recursive functions).
When doing recursions, it is the recursion depth, which is the number of iterations, that brings your computer to its limits. We demonstrate this here by considering a simple recursion, which actually contains no computations at all. It assigns to the iterates only the value zero:
def f(N): if N == 0: return 0 return f(N-1)
Depending on your system, this program may choke for (too much memory is used). The result is that the Python interpreter crashes without further exception. Python provides a mechanism to raise an exception when a too high recursion depth is detected. This maximum recursion depth may be changed by executing:
import sys sys.setrecursionlimit(1000)
Be aware though, that choosing too high a number may imperil the stability of your code since Python might crash before that maximum depth is reached. It is therefore often...