problem with an infinite loop

Alex Martelli Alex.Martelli at think3.com
Fri Dec 17 04:25:26 EST 1999


Dave Trombley writes...:

> Ionel Simionescu wrote:
	[snip]
> > The code below represents an erroneous snippet that crashes Python
> > (1.5.2/WinNT) in a very reproductible manner.
> > Maybe this kind of error can be intercepted by the interpreter and raise
> an
> > exception.
	[snip]
> > # I know this code is bad.
	[snip]
> >     def __setattr__(self, name, value):
> >         if name=='name': self.name = value
	[snip]
> The answer here is to not assign to an attribute in the usual fashion,
> ie. <object>.<name>,
> but to directly access the object's dictionary.
> 
Yep, but Ionel probably knew that -- the issue, it seems to me, is
that this error in __setattr__ is common, and having it crash the
interpreter isn't a good thing.  Perhaps it would be possible to
special-case this, or, more generally, impose some sort of
recursion limit in the interpreter's C code on those platforms
(such as NT) where erroneous unbounded recursion might
otherwise produce a crash.


Alex






More information about the Python-list mailing list