[Python-bugs-list] python dumps core on my script (PR#207)

tim_one@email.msn.com tim_one@email.msn.com
Wed, 16 Feb 2000 20:36:19 -0500 (EST)


[vincent@ldsol.com]
> If I run python p2sql.py.KICORE I get a segfault from the python
> interpreter.
> ...
> the stack trace obtained from the core file seems to indicate that the
> interpreter has gone in an infinite loop...

It's really that you've forced the interpreter into infinite recursion.
Thinking about this one should make it clear:

>>> class C:
	def __repr__(self):
		print "got into __repr__"
		return "OK"

>>> c = C()
>>> print c
got into __repr__
OK
>>>

That is, by putting "print self" into your __repr__ method, you force
never-ending recursion, because "print" implicitly invokes __repr__ again to
come up with a string representation for self, which again tries to do
"print self", which again invokes self.__repr__, etc etc.

The solution is to not do this <wink>.  It would be nice if the interpreter
caught this and raised an error, but the code doesn't make sense so you're
going to get a failure of one kind or another no matter what.