maximum recursive depth in python another danger in the misuse of recursion is known as infinite recursion if each recursive call makes another recursive callwithout ever reaching base casethen we have an infinite series of such calls this is fatal error an infinite recursion can quickly swamp computing resourcesnot only due to rapid use of the cpubut because each successive call creates an activation record requiring additional memory blatant example of an ill-formed recursion is the followingdef fib( )return fib(nfib(nequals fib(nhoweverthere are far more subtle errors that can lead to an infinite recursion revisiting our implementation of binary search in code fragment in the final case (line we make recursive call on the right portion of the sequencein particular going from index mid+ to high had that line instead been written as return binary search(datatargetmidhighnote the use of mid this could result in an infinite recursion in particularwhen searching range of two elementsit becomes possible to make recursive call on the identical range programmer should ensure that each recursive call is in some way progressing toward base case (for exampleby having parameter value that decreases with each callhoweverto combat against infinite recursionsthe designers of python made an intentional decision to limit the overall number of function activations that can be simultaneously active the precise value of this limit depends upon the python distributionbut typical default value is if this limit is reachedthe python interpreter raises runtimeerror with messagemaximum recursion depth exceeded for many legitimate applications of recursiona limit of nested function calls suffices for exampleour binary search function (section has (log nrecursive depthand so for the default recursive limit to be reachedthere would need to be elements (farfar more than the estimated number of atoms in the universehoweverin the next section we discuss several algorithms that have recursive depth proportional to python' artificial limit on the recursive depth could disrupt such otherwise legitimate computations fortunatelythe python interpreter can be dynamically reconfigured to change the default recursive limit this is done through use of module named syswhich supports getrecursionlimit function and setrecursionlimit sample usage of those functions is demonstrated as followsimport sys old sys getrecursionlimitsys setrecursionlimit( perhaps is typical change to allow million nested calls