Python enforces recursion limitations.


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.

Tags: , , , , , ,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: