On Fri, Mar 30, 2012 at 21:30, Benjamin Peterson <benja...@python.org>wrote:
> > + def test_cyclic_gc(self): > > + class ShowGC: > > + def __init__(self, flaglist): > > + self.flaglist = flaglist > > + def __del__(self): > > + self.flaglist.append(1) > > > I think a nicer way to check for cyclic collection is to take a > weakref to an object, call the GC, then check to make sure the weakref > is broken. > > > + > > + # Test the shortest cycle: lst->element->lst > > + fl = [] > > + lst = [ShowGC(fl)] > > + lst.append(ET.Element('joe', attr=lst)) > > + del lst > > + gc.collect() > > support.gc_collect() is preferable > > > + self.assertEqual(fl, [1]) > > + > > + # A longer cycle: lst->e->e2->lst > > + fl = [] > > + e = ET.Element('joe') > > + lst = [ShowGC(fl), e] > > + e2 = ET.SubElement(e, 'foo', attr=lst) > > + del lst, e, e2 > > + gc.collect() > > + self.assertEqual(fl, [1]) > > Thanks for the insights, Benjamin. I'll explore these alternatives and will submit a fix. Eli
_______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com