Python enforces recursion limitations.

by

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()

1000

. . . 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:

WordPress.com Logo

You are commenting using your WordPress.com 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: