Create new signal. Keyword Arguments: providing_args (List): A list of the arguments this signal can pass along in a :meth:`send` call. use_caching (bool): Enable receiver cache. name (str): Name of signal, used for debugging purposes.
| 71 | |
| 72 | |
| 73 | class Signal: # pragma: no cover |
| 74 | """Create new signal. |
| 75 | |
| 76 | Keyword Arguments: |
| 77 | providing_args (List): A list of the arguments this signal can pass |
| 78 | along in a :meth:`send` call. |
| 79 | use_caching (bool): Enable receiver cache. |
| 80 | name (str): Name of signal, used for debugging purposes. |
| 81 | """ |
| 82 | |
| 83 | #: Holds a dictionary of |
| 84 | #: ``{receiverkey (id): weakref(receiver)}`` mappings. |
| 85 | receivers = None |
| 86 | |
| 87 | def __init__(self, providing_args=None, use_caching=False, name=None): |
| 88 | self.receivers = [] |
| 89 | self.providing_args = set( |
| 90 | providing_args if providing_args is not None else []) |
| 91 | self.lock = threading.Lock() |
| 92 | self.use_caching = use_caching |
| 93 | self.name = name |
| 94 | # For convenience we create empty caches even if they are not used. |
| 95 | # A note about caching: if use_caching is defined, then for each |
| 96 | # distinct sender we cache the receivers that sender has in |
| 97 | # 'sender_receivers_cache'. The cache is cleaned when .connect() or |
| 98 | # .disconnect() is called and populated on .send(). |
| 99 | self.sender_receivers_cache = ( |
| 100 | weakref.WeakKeyDictionary() if use_caching else {} |
| 101 | ) |
| 102 | self._dead_receivers = False |
| 103 | |
| 104 | def _connect_proxy(self, fun, sender, weak, dispatch_uid): |
| 105 | return self.connect( |
| 106 | fun, sender=sender._get_current_object(), |
| 107 | weak=weak, dispatch_uid=dispatch_uid, |
| 108 | ) |
| 109 | |
| 110 | def connect(self, *args, **kwargs): |
| 111 | """Connect receiver to sender for signal. |
| 112 | |
| 113 | Arguments: |
| 114 | receiver (Callable): A function or an instance method which is to |
| 115 | receive signals. Receivers must be hashable objects. |
| 116 | |
| 117 | if weak is :const:`True`, then receiver must be |
| 118 | weak-referenceable. |
| 119 | |
| 120 | Receivers must be able to accept keyword arguments. |
| 121 | |
| 122 | If receivers have a `dispatch_uid` attribute, the receiver will |
| 123 | not be added if another receiver already exists with that |
| 124 | `dispatch_uid`. |
| 125 | |
| 126 | sender (Any): The sender to which the receiver should respond. |
| 127 | Must either be a Python object, or :const:`None` to |
| 128 | receive events from any sender. |
| 129 | |
| 130 | weak (bool): Whether to use weak references to the receiver. |
no outgoing calls
no test coverage detected