weakref.WeakMethod

class weakref.WeakMethod(method) A custom ref subclass which simulates a weak reference to a bound method (i.e., a method defined on a class and looked up on an instance). Since a bound method is ephemeral, a standard weak reference cannot keep hold of it. WeakMethod has special code to recreate the bound method until either the object or the original function dies: >>> class C: ... def method(self): ... print("method called!") ... >>> c = C() >>> r = w

weakref.ref

class weakref.ref(object[, callback]) Return a weak reference to object. The original object can be retrieved by calling the reference object if the referent is still alive; if the referent is no longer alive, calling the reference object will cause None to be returned. If callback is provided and not None, and the returned weakref object is still alive, the callback will be called when the object is about to be finalized; the weak reference object will be passed as the only parameter to the

weakref.WeakKeyDictionary

class weakref.WeakKeyDictionary([dict]) Mapping class that references keys weakly. Entries in the dictionary will be discarded when there is no longer a strong reference to the key. This can be used to associate additional data with an object owned by other parts of an application without adding attributes to those objects. This can be especially useful with objects that override attribute accesses. Note Caution: Because a WeakKeyDictionary is built on top of a Python dictionary, it must no

weakref.ReferenceError

exception weakref.ReferenceError Exception raised when a proxy object is used but the underlying object has been collected. This is the same as the standard ReferenceError exception.

weakref.WeakSet

class weakref.WeakSet([elements]) Set class that keeps weak references to its elements. An element will be discarded when no strong reference to it exists any more.

weakref.WeakKeyDictionary.keyrefs()

WeakKeyDictionary.keyrefs() Return an iterable of the weak references to the keys.

weakref.finalize.peek()

peek() If self is alive then return the tuple (obj, func, args, kwargs). If self is dead then return None.

weakref.getweakrefcount()

weakref.getweakrefcount(object) Return the number of weak references and proxies which refer to object.

weakref.ProxyTypes

weakref.ProxyTypes Sequence containing all the type objects for proxies. This can make it simpler to test if an object is a proxy without being dependent on naming both proxy types.

weakref.finalize.__call__()

__call__() If self is alive then mark it as dead and return the result of calling func(*args, **kwargs). If self is dead then return None.