Maximum recursion depth reached in Python

Previous
Next

In this post, we will see about Maximum recursion depth reached in Python.This can be solved by increase the recursion depth in python.

If you are getting Runtime error Maximum recursion depth reached. then you can increase default recursion depth which is by default 1000.
You need to import sys module in your script and put following code.

It will increase default recursion depth to 1500.

But I won’t recommend using this tactic instead you should rewrite your algorithm to an iterative one if possible. Python does not optimize tail recursion and uncontrolled recusion causes stack overflows.

For example:
Instead of fibonacci recusive algoroithm

You can use iterative algorithm.

That’s all about Maximum recursion depth reached in Python.

Previous
Next

Join Our News Letter – Stay Updated

Subscribe to Awesome Java Content.




Add Comment

Join Our News Letter - Stay Updated

Subscribe to Awesome Java Content.
You can like our facebook page Java2blog