pydispatch.utils module

WeakMethodContainer class

class WeakMethodContainer(**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

Remove any stored instance methods that belong to an object

Parameters:obj – The instance object to remove

Remove an instance method or function if it exists

Parameters:m – The instance method or function to remove

Iterate over the stored objects

Yields:wrkey – The two-tuple key used to store the object obj: The instance or function object

Iterate over stored functions and instance methods

Yields:Instance methods or function objects
keys() → a set-like object providing a view on D's keys[source]

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: pydispatch.utils.EmissionHoldLock_, pydispatch.aioutils.AioEmissionHoldLock

EmissionHoldLock_ class

class EmissionHoldLock_(event_instance)[source]

Context manager used for pydispatch.dispatch.Dispatcher.emission_lock()

Parameters:event_instance – The Event instance associated with the lock

The Event instance associated with the lock


The positional and keyword arguments from the event’s last emission as a two-tuple. If no events were triggered while the lock was held, None.


bool – The internal state of the lock

AioEmissionHoldLock class

class AioEmissionHoldLock[source]

Bases: object

Async context manager mixin for pydispatch.utils.EmissionHoldLock_

Supports use in async with statements