• Register
0 votes
573 views

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

Solution:

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:

sys.setrecursionlimit(limit):

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:

https://github.com/python/typing/issues/523

9 7 4
38,600 points
0 votes

Solution:

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:
		utime.sleep_ms(delta)

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

Solution:

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
sys.setrecursionlimit(10**6) 
def fact(n):
	if(n == 0):
		return 1
	return n * fact(n - 1)
if __name__ == '__main__':
	f = int(input('Enter the number: \n'))
	print(fact(f))

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 49 views
49 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 49 views
49 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 3 views
3 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 5.6k points
0 votes
1 answer 1.9K views
1.9K views
Problem : I had to remove a +CompatEnvVars from following : SSLOptions +FakeBasicAuth +ExportCertData +CompatEnvVars +StrictRequire As it said it was an invalid command or something. So having removed that and following a instructions to a nail it get below error: ... maximum permissible length. (Error code: ssl_error_rx_record_too_long) I am very new to SSL, any advice on what is going wrong?
asked Jan 17, 2020 jwilliam 3.9k points
0 votes
1 answer 3 views
3 views
Problem Hey, I need help from you. Is there any way to call python from java. I mean how can we run a python program from java.
asked 3 days ago chris jordan 2.2k points
0 votes
2 answers 1.1K views
1.1K views
Problem : I am new to Py 3.5. This code was working properly in Python 2.7: with open(fname, 'rb') as f: lines = [x.strip() for x in f.readlines()] for line in lines: tmp = line.strip().lower() if 'some-pattern' in tmp: continue # ... code After upgrading to 3.5, I'm getting the: TypeError: a bytes-like object is required, not 'str'
asked Oct 22, 2019 peterlaw 6.9k points
0 votes
1 answer 4 views
4 views
Problem Hey, want to ask you how to resolve an error named Run Time Error ‘2501’. Can someone help me to fix this error. The Report is called through this code Private Sub Command92_Click()     DoCmd.SetWarnings Off     ''# get ... ", acNormal     DoCmd.GoToRecord acDataForm, "NewReqVersionForm", acLast End Sub Private Sub StatusID_Change()     Me.LastModifiedTimeStamp = Now() End Sub
asked 6 days ago chris jordan 2.2k points
0 votes
1 answer 4 views
4 views
Problem: What is the difference between compile time error and runtime error?
asked Dec 20, 2020 prog_learner 2.5k points
0 votes
1 answer 12 views
12 views
Problem: hello Everyone, We are working on the firebase based real-time messaging application and we are encountering this error whenever we try to run our application. The compiler we are using is Xode11 and the language version is swift 5. Your valuable response is welcomed. Thanks
asked Oct 12, 2020 SapperIt 1.2k points
0 votes
1 answer 97 views
97 views
I have been stuck to sort out this issue for a long time and even after reading a number of posts. Can some one help to sort out this issue and give me the reason why this is happening in this case?
asked Sep 14, 2020 Daniel Anderson 4k points