473,387 Members | 1,693 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,387 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 44919
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.