[Python-Dev] Re: [Python-checkins]python/dist/src/Modules gcmodule.c,188.8.131.52,184.108.40.206
Sat, 5 Apr 2003 14:34:36 -0500
I checked in some more changes (2.3 head only). This kind of program may be
def __getattr__(self, attribute):
if 'attr' in self.__dict__:
a = C()
b = C()
alist = 
a.attr = b
b.attr = a
a.x = 1
b.x = 2
del a, b
# Oops. This prints 4: it's collecting
# a, b, and their dicts.
# Despite that __getattr__ resurrected them.
# But gc cleared their dicts.
# So a.x and b.x fail.
print alist.x, alist.x
While a __getattr__ side effect may resurrect an object in gc's unreachable
list, gc has no way to know that an object has been resurrected short of
starting over again. In the absence of that, the object remains in gc's
unreachable list, and its tp_clear slot eventually gets called. The
internal C stuff remains self-consistent, so this won't cause a segfault
(etc), but it may (as above) be surprising. I don't see a sane way to fix
this so long as asking whether __del__ exists can execute arbitrary mounds
of Python code.