Posts Tagged ‘bugs’

Python enforces recursion limitations.

November 15, 2010

Python has limits on recursion depth.  This is a nice language feature because it prevents infinite loops from exploding your runtime, but it can be problematic when dealing with deep data structures and/or graph traversal.

If you see this error. . .

RuntimeError: maximum recursion depth exceeded

. . . don’t freak out.  Instead, try increasing the recursion limit.  First, find the current limit:

>>> import sys

>>> sys.getrecursionlimit()


. . . and then increase the limit:

>>> sys.setrecursionlimit(10000)

In my case, I changed the limit from 1000 to 10000, but obviously the appropriate numbers might be different for your problem.


The dance of bolas spider with its prey

March 6, 2009