• Register
0 votes

Problem :

I am getting below error
maximum recursion depth exceeded while calling a python object

6 5 3
6,930 points

Please log in or register to answer this question.

3 Answers

0 votes


Python lacks the tail recursion optimizations which is common in functional languages like lisp. In Python, recursion is limited to 999 calls 

1) You can change the recursion limit with sys.setrecursionlimit(n) until the maximum allowed for your platform:


2) You can try to convert the algorithm from recursive to iterative. If recursion depth is bigger than allowed by your platform, it is the only way to fix the problem. 

Further Readings:


9 7 4
38,600 points
0 votes


You'll trace flashbdev.py in the source tree esp826/modules. It would appear to be the low level driver for the flash memory - my guess is that the readblocks system is being named recursively probably owing to re-entrant code. At the time you change parameters is there a situation where a timer callback implements prior another has finished accessing a file?

Accessing files in an interrupt handler is a bad idea since file access times are not deterministic. More, code in interrupt handlers such as timer callbacks must be designed to implement fast.

I would possibly avoid employing a timer and only run a loop which achieves its timing like this:

import utime
while True:
	tstart = utime.ticks_ms()
	# do all your stuff
	delta = 150 - utime.ticks_diff(utime.ticks_ms(), tstart)
	if delta > 0:

I raised the recursion limit by one and got the similar exception. After rising it to 5000 (1000 is the default) I no longer view it. Maybe I require to do few digging in my code because I am making many temporary objects in each iteration of an event loop.

Figurred out an infinite recursion problem in an overridden _getattr_ in my code and after solving this I no longer view this exception. You may mark this bug as green or delete it.

10 6 4
31,120 points
1 vote


When you run a recursive function in Python on a large input ( > 10^4), you might face a “maximum recursion depth exceeded error”. This is a common scenario for a program when someone tries to run a program with a more extensive input range. To avoid the error, you can call the setrecursionlimit() function from the sys module in Python. This particular function modifies the recursion limit in Python. Using this function, we can set your recursion limit 10**6 to avoid the error. Let’s see how it works:

import sys
def fact(n):
	if(n == 0):
		return 1
	return n * fact(n - 1)
if __name__ == '__main__':
	f = int(input('Enter the number: \n'))

Boom! Now you’ve increased the limit, and the program can calculate the factorial up to 10**6 range number. I hope this example will help you to understand.

13 9 6
94,240 points

Related questions

0 votes
1 answer 55 views
Problem : I am trying to write my first program in Vpython and I have to make the simulation of mixing two gases. First I had the problem with borders, but now when my balls(that represents a gas particles) stay within a border there is the sth different wrong. ... ) for j in range(0,len(self.listOfBalls)): self.listOfBalls[j].pos=poruszanie(self.listOfBalls,self.listOfBalls[j].pos,self.numCell,0)
asked Jan 23, 2020 jwilliam 3.9k points
0 votes
1 answer 64 views
Problem: I am new to python programming and I am little bit bit confused about some things like I wrote a code: def random(): a = random.randint (0, x+1) b = random.randint (0, y+1) c = random.randint (0, z+1) outer_function(a,b,c ... recursion depth exceeded while calling a Python object IndentationError: expected an indented block I am confused about those things, why is this error shown to me ?
asked Mar 22, 2020 LizzyM 6.1k points
0 votes
1 answer 8 views
maximum recursion depth exceeded while calling a python object
asked Feb 16 ArifulIslam 7.5k points
0 votes
1 answer 12 views
Problem: How to I Solve this: runtimeerror maximum recursion depth exceeded in cmp HELP! I need help understanding this: runtimeerror maximum recursion depth exceeded in cmp Can someone please help solve this, I am new in python(). Someone have idea to solve this thanks!
asked Mar 7 Mashhoodch 13k points
0 votes
1 answer 13 views
recursionerror: maximum recursion depth exceeded in comparison
asked Feb 16 ArifulIslam 7.5k points
0 votes
1 answer 9 views
Problem: I've got error message > chromedriver' executable needs to be in path.
asked Apr 1 Azlan2020 2.3k points
0 votes
1 answer 31 views
Problem: I'm new to programming and started with Python about two months ago and am going over Sweigart's Automate the Boring Stuff with Python text. I'm using IDLE and already installed the Selenium module and the Firefox browser. Whenever I tried to run the webdriver function, I get this: from selenium import webdriver browser = webdriver.Firefox()
asked Jan 6 Mashhoodch 13k points
0 votes
1 answer 2 views
Problem: When I try to execute this code, it runs upto the first document and at the second document, it stops with an error. This says, “error 91 object variable or with block variable not set.” Help me out.
asked 4 days ago muktaa 4.9k points
0 votes
1 answer 5 views
I am beginner in this field and when i faced this problem on my pc then i decided to not to do more tried by which this problem can extend and i am posting here my problem right now, can anyone help me out?
asked Apr 4 niyatiry 3.2k points
0 votes
1 answer 4 views
Problem: I am testing code before adding it to an existing project. Then I added the lines below and it fails with the 424 error: Run time error 424 object required vb
asked Mar 27 ummesalma 25.2k points