See More

import weakref import new class methodref(weakref.ref): def __new__(cls, method, callback=None): if not isinstance(method, new.instancemethod): raise TypeError, 'instancemethod expected; got %s instead' % type(method) wr = super(methodref, cls).__new__(cls, method.im_self, callback) wr.im_func = method.im_func wr.im_class = method.im_class return wr def __call__(self): im_self = super(methodref, self).__call__() if im_self is not None: return new.instancemethod(self.im_func, im_self, self.im_class) class cls1: def giveTo(self, to): to.take(self.bla) def bla(self, arg): print self, "says", arg class cls2: def take(self, what): self.ref = methodref(what) c1 = cls1() c2 = cls2() print weakref.getweakrefs(c1) c1.giveTo(c2) print weakref.getweakrefs(c1) print c1.bla print c2.ref c1.bla("hi") c2.ref()("hello")