473,289 Members | 1,723 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,289 software developers and data experts.

RuntimeError 'maximum recursion depth exceeded'

Sometimes I get this error.
E.g.
sum = lambda n: n<=1 or n+sum(n-1) # just to illustrate the error
sum(999) 499500 sum(1000)

............
RuntimeError: maximum recursion depth exceeded

Is there any way to set a bigger stack in Python?

G-:
--
Georgy Pruss
E^mail: 'ZDAwMTEyMHQwMzMwQGhvdG1haWwuY29t\n'.decode('base6 4')
Jul 18 '05 #1
6 44910
Georgy Pruss wrote:
Sometimes I get this error.
E.g.

sum = lambda n: n<=1 or n+sum(n-1) # just to illustrate the error
sum(999)
499500
sum(1000)


...........
RuntimeError: maximum recursion depth exceeded

Is there any way to set a bigger stack in Python?

G-:


See

sys.getrecursionlimit(), and
sys.setrecursionlimit(limit)

doco at:

http://python.org/doc/current/lib/module-sys.html

a quick search of the doco or the newsgroup archive at:
http://groups.google.com/groups?hl=e...mp.lang.python

would have found the answer.

Regards,

Ray Smith

Jul 18 '05 #2
Georgy Pruss wrote:
RuntimeError: maximum recursion depth exceeded

Is there any way to set a bigger stack in Python?

Yep: sys.setrecursionlimit

--Irmen

Jul 18 '05 #3
Thank you.
Now it's "MemoryError: Stack overflow" but it's another story. :)
G-:

"Irmen de Jong" <irmen@-NOSPAM-REMOVETHIS-xs4all.nl> wrote in message news:3f***********************@news.xs4all.nl...
| Georgy Pruss wrote:
|
| > RuntimeError: maximum recursion depth exceeded
| >
| > Is there any way to set a bigger stack in Python?
|
|
| Yep: sys.setrecursionlimit
|
| --Irmen
|
Jul 18 '05 #4
Georgy Pruss wrote:
Thank you.
Now it's "MemoryError: Stack overflow" but it's another story. :)


Hmm, what are you doing exactly that requires this deep recursion?
Can't you rewrite your algorithm in a non-recursive way?

--Irmen

Jul 18 '05 #5
No, I'm not complaining. It's good that Python doesn't just freeze or crash.
The algorithm is "deep first" walk in a maze, so for 100x100 mazes the
recursion is well deeper than 1000 levels and the stack is not big enough indeed.
Of course, for big dimentions the algorithm needs to be re-written w/o recursion.

Georgy Pruss
--
p='p=;print p[:2]+chr(39)+p+chr(39)+p[2:]';print p[:2]+chr(39)+p+chr(39)+p[2:]
"Irmen de Jong" <irmen@-NOSPAM-REMOVETHIS-xs4all.nl> wrote in message news:3f***********************@news.xs4all.nl...
| Georgy Pruss wrote:
| > Thank you.
| > Now it's "MemoryError: Stack overflow" but it's another story. :)
|
| Hmm, what are you doing exactly that requires this deep recursion?
| Can't you rewrite your algorithm in a non-recursive way?
|
| --Irmen
|
Jul 18 '05 #6
Georgy Pruss wrote:
Sometimes I get this error.
E.g.
sum = lambda n: n<=1 or n+sum(n-1) # just to illustrate the error
sum(999) 499500 sum(1000)

...........
RuntimeError: maximum recursion depth exceeded

Is there any way to set a bigger stack in Python?


Yes, use sys.setrecursionlimit()
See http://www.python.org/dev/doc/devel/lib/module-sys.html :

setrecursionlimit(limit)
Set the maximum depth of the Python interpreter stack to limit. This limit prevents infinite recursion from causing an overflow of the C stack and crashing Python.

The highest possible limit is platform-dependent. A user may need to set the limit higher when she has a program that requires deep recursion and a platform that supports a higher limit. This should be done with care, because a too-high limit can lead to a crash.

Note that in this case, you can simlpy use the builtin sum:
See http://www.python.org/dev/doc/devel/...-in-funcs.html :

sum(sequence[, start])
Sums start and the items of a sequence, from left to right, and returns the total. start defaults to 0. The sequence's items are normally numbers, and are not allowed to be strings. The fast, correct way to concatenate sequence of strings is by calling ''.join(sequence). Note that sum(range(n), m) is equivalent to reduce(operator.add, range(n), m) New in version 2.3.

....but I assume you already knew the latter, since you said that you example
was just to illustrate the error. Just to be sure.

yours,
Gerrit.

--
This space intentionally left blank.
--
Asperger Syndroom - een persoonlijke benadering:
http://people.nl.linux.org/~gerrit/
Kom in verzet tegen dit kabinet:
http://www.sp.nl/

Jul 18 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Bill Loren | last post by:
Hi ppl, Trying to substitute some html tags within a big html file using RE ended up with the "RuntimeError: maximum recursion limit exceeded" message. Any idea why that might happen and how...
2
by: Sujit Marar | last post by:
When I run on Webware(Python application Server), there is a web Page that has a "Cancel" button , When I press the Cancel button , I get the following error based on the following code snippet...
4
by: Dan | last post by:
I've encountered some strange behavior in a recursive procedure I'm writing for a bill of materials. First let me ask directly if what I think is happening is even possible: It seems like the...
5
by: yogee | last post by:
Hi, I want to know if we have any limit for calling any function recoursively. If there is any, On what parameters this limit depends? and is it different for .net 1.0, 1.1 and 2.0? Thank you,...
14
by: olekristianvillabo | last post by:
I have a regular expression that is approximately 100k bytes. (It is basically a list of all known norwegian postal numbers and the corresponding place with | in between. I know this is not the...
10
by: MakeMineScotch | last post by:
What's the secret to writing recursive functions that won't crash the computer?
0
by: cwig | last post by:
The following code fails: <?xml version="1.0" encoding="iso-8859-1"?> <!-- Based on a template found here: http://www.stylusstudio.com/xsllist/200303/post91230.html --> <xsl:stylesheet...
0
by: jobs | last post by:
re: Oracle Exceeded maximum idle time I have asp.net web gridview that is populated by a function that calls an Oracle procedure that returns a dataset. At most, it might take 2 or 4 seconds to...
6
by: globalrev | last post by:
i received an error maximum recursion depth when processing large amounts of data. i dont know exactly how many recursive calls i made but id assume 50000 or so. is there a definitie limit...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.