[Tutor] Re: rre: Recursion error
Mike Wagman
mwagman at charter.net
Wed Oct 1 06:40:52 EDT 2003
I got up to 999 then got
File "count.py", line 4, in test
test(count)
RuntimeError: maximum recursion depth exceeded
On Wed, 2003-10-01 at 00:43, Andrei wrote:
> Kirk Bailey wrote:
>
> > Well, I tried this:
> >
> > def test(count):
> > print count
> > count=count+1
> > test(count)
>
> Tried that only I do the count increase inside the function call.
>
> > and when the count got to 346, I chickened out and hit ^C, and got a
>
> Got up to 984, nothing interesting happens:
>
> 983
> 984
> Traceback (most recent call last):
> File "<input>", line 1, in ?
> File "<input>", line 3, in test
>
> I don't have to wait at all, the traceback appears virtually instantaneously. I
> couldn't even stop it at 300 if I wanted to :). But that's in wxPython, perhaps
> Tk is slower and that's why you didn't get that far. The limit seems to be
> pretty much fixed, memory use is negligeable.
>
> > HUGE error report back. I will spare the list. But it went WELL past 50
> > recursions. Of course, this was a small and simple function, and did not
> > tax the stack at all heavily per recursion.
>
> Tried more memory consuming test too:
>
> >>> class X(object):
> ... def __init__(self, i):
> ... self.list = [10,10,10,10,10,10,10,10,10,10]*i
> ...
> >>> def test(i):
> ... l.append(X(i))
> ... print i
> ... test(i+1)
> ...
> >>> l = []
> >>> test(0)
> <snip output and traceback>
> >>> len(l[-1].list)
> 9850
>
> Stops at 984 too, but eats about 22MB of mem.
More information about the Tutor
mailing list