All pastes #2053436 Raw Edit

Anonymous

public text v1 · immutable
#2053436 ·published 2011-05-03 12:04 UTC
rendered paste body
~ $ cat test.py
from snakeoil.weakrefs import WeakRefFinalizer
import gc

class foo(object):
    __metaclass__ = WeakRefFinalizer
    def __init__(self, attr):
        self.attr = attr
    def __del__(self):
        print("finalization invoked:", self.attr)


def test():
    f = foo("foo")
    b = foo("bar")
    f.b = b
    b.f = f

test()
gc.collect()
print("here")
~ $ python2.7 test.py
here
~ $ python3.1 test.py
here