weakref confusion

Mathias Mamsch Domoran at yahoo.de
Wed Feb 25 18:36:59 CET 2004


Hi,

I have some confusion concerning the weakref module.
I am trying to save a weak reference to a bound  member function of a class
instance for using it as a callback function. But I always get dead
references, when I try to create a reference to a bound member function. It
seems as if an instance of a class owns no reference to its memberfunctions,
so the the reference count is always zero. How can I come behind that?


If I do:
----------------
import weakref

class A:
    def Test(data): print data

def MyTest (data): print data
AInst = A()

x = weakref.ref (AInst.Test)   # x is a dead reference
y = weakref.ref (MyTest) # y is a working reference
f = AInst.Test
z = weakref.ref(f)        # z works ...
del f                            # now z dies ....
----------------





More information about the Python-list mailing list