473,498 Members | 1,776 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

maximum recursion depth?

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 to the nbr of calls or is the memory that
runs out? is that then the RAMmemory? is there a special amount of
memory assigned for python or it just takes and takes until windows
runs out of it?
Jun 27 '08 #1
6 17831
On May 28, 9:26 am, globalrev <skanem...@yahoo.sewrote:
is there a definitie limit to the nbr of calls or is the memory that
runs out? is that then the RAMmemory? is there a special amount of
memory assigned for python or it just takes and takes until windows
runs out of it?
You can alter the recursion limit using sys.setrecursionlimit:

setrecursionlimit(n)

Set the maximum depth of the Python interpreter stack to n. This
limit prevents infinite recursion from causing an overflow of the
C
stack and crashing Python. The highest possible limit is
platform-
dependent.
Jun 27 '08 #2
alex23 wrote:
On May 28, 9:26 am, globalrev <skanem...@yahoo.sewrote:
>is there a definitie limit to the nbr of calls or is the memory that
runs out? is that then the RAMmemory? is there a special amount of
memory assigned for python or it just takes and takes until windows
runs out of it?

You can alter the recursion limit using sys.setrecursionlimit:

setrecursionlimit(n)

Set the maximum depth of the Python interpreter stack to n. This
limit prevents infinite recursion from causing an overflow of the
C
stack and crashing Python.
The default is rather low. I've actually hit it parsing big HTML
files with BeautifulSoup.

John Nagle
Jun 27 '08 #3
Dennis Lee Bieber, the ghost:
I'd have to wonder why so many recursive calls?
Why not? Maybe the algorithm is written in a recursive style. A
language is good if allows you to use that style too.
On modern CPUs 50000 levels don't look that many levels.

Bye,
bearophile
Jun 27 '08 #4
On Wed, 28 May 2008 02:28:54 -0700, bearophileHUGS wrote:
Dennis Lee Bieber, the ghost:
>I'd have to wonder why so many recursive calls?

Why not?
Because of the recursion limit of course. And function call overhead in
Python is quite high compared to an iterative approach.

Ciao,
Marc 'BlackJack' Rintsch
Jun 27 '08 #5
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

[ Marc 'BlackJack' Rintsch <bj****@gmx.net]
On Wed, 28 May 2008 02:28:54 -0700, bearophileHUGS wrote:
>Dennis Lee Bieber, the ghost:
>>I'd have to wonder why so many recursive calls?

Why not?

Because of the recursion limit of course. And function call overhead in
Python is quite high compared to an iterative approach.
And limiting the recursion depth is quite reasonable: The python interpreter
doesn't perform tail call optimisation, each level of recursion depth eats
a bit more memory. Without a recursion limit a python process might hit
the memory restrictions of the OS kernel, which would cause the OS kernel
to just silently kill the interpreter process. Now image this happening
inside a mission critical server process ;)
- --
Freedom is always the freedom of dissenters.
(Rosa Luxemburg)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)

iEYEARECAAYFAkg9nFQACgkQn3IEGILecb5ziQCfe7BcH/7hzMH/6QmGcFy0qQGd
cGoAn0dM0fkErYTs4zlY6kDYdOBEN8+D
=cWxH
-----END PGP SIGNATURE-----
Jun 27 '08 #6
* Marc 'BlackJack' Rintsch:
On Wed, 28 May 2008 02:28:54 -0700, bearophileHUGS wrote:
>Dennis Lee Bieber, the ghost:
>>I'd have to wonder why so many recursive calls?

Why not?

Because of the recursion limit of course. And function call overhead in
Python is quite high compared to an iterative approach.
One of my pet projects[1, it's about building and searching trees] made
heavy use of recursion in the beginning. I rewrote parts of it using
iteration because I hit the recursion limit and suspected a performance
hit as well. To my (mild) surprise, the rewrite didn't perform
significantly better. My benchmarks only showed an improvement of a few
percent in runtime. I didn't measure memory usage, though.

J.

[1] http://well-adjusted.de/mspace.py/
(Sorry, baerophile, I'll get back to you about this! My SNV working
copy is currently a mess and I need to clean that up first.)

--
I feel yawning hollowness whilst talking to people at parties.
[Agree] [Disagree]
<http://www.slowlydownward.com/NODATA/data_enter2.html>
Jun 27 '08 #7

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

Similar topics

0
1939
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...
1
5077
by: Simon Burton | last post by:
Hi, I am pickling big graphs of data and running into this problem: File "/usr/lib/python2.2/pickle.py", line 225, in save f(self, object) File "/usr/lib/python2.2/pickle.py", line 414, in...
6
44927
by: Georgy Pruss | last post by:
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...
2
2621
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
2211
by: Ingo Nolden | last post by:
Hi, I want to write a template class that holds another class that uses the same template. This recursion should stop after a predefined number. I think it's either impossible or easy, but I...
0
1488
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...
24
2508
by: proctor | last post by:
hello, i have a small function which mimics binary counting. it runs fine as long as the input is not too long, but if i give it input longer than 8 characters it gives RuntimeError: maximum...
4
4014
by: TK | last post by:
Hi, is there a way to change the recursion depth for a function/method? In Python can I do it: import sys sys.setrecursionlimit(1500) Thanks for help.
7
4912
by: Mark Riphenburg | last post by:
Hello, I'm working on a project where I need to count the current recursion depth of a macro to abstract recursion so that given instances don't collide. The idea is to provide say 8 instances of...
0
7125
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
7004
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
7208
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...
1
6890
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7379
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
3095
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3085
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
657
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
292
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.