PyDocs

Nav

Data Types

WeakMethod

weakref

class · Added in 3.4 (source)
  • WeakMethod(method[, callback])
A custom `weakref.ref` subclass which simulates a weak reference to
a bound method, working around the lifetime problem of bound methods.
1 Example
>>> class C:
...     def method(self):
...         print("method called!")
...
>>> c = C()
>>> r = weakref.ref(c.method)
>>> r()
>>> r = weakref.WeakMethod(c.method)
>>> r()
<bound method C.method of <__main__.C object at 0x7fc859830220>>
>>> r()()
method called!
>>> del c
>>> gc.collect()
0
>>> r()
>>>
from the Python docs
See Also
No see-alsos for weakref/WeakMethod
0 Notes
No notes for WeakMethod