Implementation of the Observer pattern.
||Get weakref constructor appropriate for obj. obj may be a bound method.|
Get weakref constructor appropriate for obj. obj may be a bound method.
Bound method objects must be special-cased because they’re usually garbage collected immediately, even if the instance they’re bound to persists.
- a (weakref constructor, main object) tuple. weakref constructor is
weakref.WeakMethod. main object is the instance that obj is bound to if it is a bound method; otherwise main object is simply `obj.
_make_lookup_key(receiver, sender, dispatch_uid)¶
Signal(providing_args=None, use_caching=False, name=None)¶
Create new signal.
- Keyword Arguments:
- providing_args (List): A list of the arguments this signal can pass
- along in a
use_caching (bool): Enable receiver cache. name (str): Name of signal, used for debugging purposes.
__init__(providing_args=None, use_caching=False, name=None)¶
_connect_proxy(fun, sender, weak, dispatch_uid)¶
Connect receiver to sender for signal.
- receiver (Callable): A function or an instance method which is to
receive signals. Receivers must be hashable objects.
if weak is
True, then receiver must be weak-referenceable.
Receivers must be able to accept keyword arguments.
If receivers have a dispatch_uid attribute, the receiver will not be added if another receiver already exists with that dispatch_uid.
- sender (Any): The sender to which the receiver should respond.
- Must either be a Python object, or
Noneto receive events from any sender.
- weak (bool): Whether to use weak references to the receiver.
- By default, the module will attempt to use weak references to the receiver objects. If this parameter is false, then strong references will be used.
- dispatch_uid (Hashable): An identifier used to uniquely identify a
- particular instance of a receiver. This will usually be a string, though it may be anything hashable.
- retry (bool): If the signal receiver raises an exception
- (e.g. ConnectionError), the receiver will be retried until it runs successfully. A strong ref to the receiver will be stored and the weak option will be ignored.
_connect_signal(receiver, sender, weak, dispatch_uid)¶
disconnect(receiver=None, sender=None, weak=None, dispatch_uid=None)¶
Disconnect receiver from sender for signal.
If weak references are used, disconnect needn’t be called. The receiver will be removed from dispatch automatically.
- receiver (Callable): The registered receiver to disconnect.
- May be none if dispatch_uid is specified.
sender (Any): The registered sender to disconnect.
weak (bool): The weakref state to disconnect.
- dispatch_uid (Hashable): The unique identifier of the receiver
- to disconnect.
Send signal from sender to all connected receivers.
If any receiver raises an error, the error propagates back through send, terminating the dispatch loop, so it is quite possible to not have all receivers called if a raises an error.
- sender (Any): The sender of the signal.
- Either a specific object or
**named (Any): Named arguments which will be passed to receivers.
- List: of tuple pairs: [(receiver, response), … ].
Filter sequence of receivers to get resolved, live receivers.
This checks for weak references and resolves them, then returning only live receivers.
Remove dead receivers from connections.