pydispatch.utils
#
WeakMethodContainer class#
- class WeakMethodContainer(other=(), /, **kw)[source]#
Container to store weak references to callbacks
Instance methods are stored using the underlying function object and the instance id (using
id(obj)
) as the key (a two-tuple) and the object itself as the value. This ensures proper weak referencing.Functions are stored using the string “function” and the id of the function as the key (a two-tuple).
- add_method(m, **kwargs)[source]#
Add an instance method or function
- Parameters
m – The instance method or function to store
- del_instance(obj)[source]#
Remove any stored instance methods that belong to an object
- Parameters
obj – The instance object to remove
- del_method(m)[source]#
Remove an instance method or function if it exists
- Parameters
m – The instance method or function to remove
InformativeWVDict class#
- class InformativeWVDict(**kwargs)[source]#
Bases:
weakref.WeakValueDictionary
A WeakValueDictionary providing a callback for deletion
- Keyword Arguments
del_callback – A callback function that will be called when an item is either deleted or dereferenced. It will be called with the key as the only argument.
EmissionHoldLock class#
- class EmissionHoldLock(event_instance)[source]#
Bases:
object
Context manager used for
pydispatch.dispatch.Dispatcher.emission_lock()
Supports use as a context manager used in
with
statements and an asynchronous context manager when used inasync with
statements.- Parameters
event_instance – The
Event
instance associated with the lock