[Python-Dev] stack check on Unix: any suggestions?

M.-A. Lemburg mal@lemburg.com
Thu, 31 Aug 2000 17:24:58 +0200


Guido van Rossum wrote:
> 
> > Here's a sample script:
> >
> > i = 0
> > def foo(x):
> >     global i
> >     print i
> >     i = i + 1
> >     foo(x)
> >
> > foo(None)
> 
> Please try this again on various platforms with this version:
> 
>     i = 0
>     class C:
>       def __getattr__(self, name):
>           global i
>           print i
>           i += 1
>           return self.name # common beginners' mistake
> 
>     C() # This tries to get __init__, triggering the recursion
> 
> I get 5788 iterations on Red Hat Linux 6.2 (ulimit -c says 8192; I
> have no idea what units).

8192 refers to kB, i.e. 8 MB.

I get 6053 on SuSE Linux 6.2 without resource stack limit set.

Strange enough if I put the above inside a script, the class
isn't instantiated. The recursion only starts when I manually
trigger C() in interactive mode or do something like
'print C()'. Is this a bug or a feature ?

-- 
Marc-Andre Lemburg
______________________________________________________________________
Business:                                      http://www.lemburg.com/
Python Pages:                           http://www.lemburg.com/python/