473,379 Members | 1,187 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,379 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 44918
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.