Signal
Create new signal.
Attributes
| Attribute | Type | Description |
|---|---|---|
| receivers | dict = None | Holds a dictionary of {receiverkey (id): weakref(receiver)} mappings. |
| providing_args | set | A set of the arguments this signal can pass along in a send call. |
| lock | threading.Lock | A threading lock used to ensure thread-safe access when connecting, disconnecting, or clearing receivers. |
| use_caching | bool | Enable receiver cache to improve performance by storing receivers for distinct senders. |
| name | str | Name of signal, used for debugging purposes. |
| sender_receivers_cache | dict | A cache mapping senders to their associated receivers, implemented as a WeakKeyDictionary if caching is enabled. |
Constructor
Signature
def Signal(
providing_args: List = None,
use_caching: bool = False,
name: str = None
) - > null
Parameters
| Name | Type | Description |
|---|---|---|
| providing_args | List = None | A list of the arguments this signal can pass along in a send call. |
| use_caching | bool = False | Enable receiver cache to improve performance for repeated sends. |
| name | str = None | Name of the signal, used for debugging purposes. |
Methods
connect()
@classmethod
def connect(
*args: Any,
**kwargs: Any
) - > Callable
Connect receiver to sender for signal.
Parameters
| Name | Type | Description |
|---|---|---|
| *args | Any | Positional arguments, typically the receiver function. |
| **kwargs | Any | Keyword arguments including sender, weak, dispatch_uid, and retry. |
Returns
| Type | Description |
|---|---|
Callable | The registered receiver function or a decorator if called without a receiver. |
disconnect()
@classmethod
def disconnect(
receiver: Callable = null,
sender: Any = null,
weak: bool = null,
dispatch_uid: Hashable = null
) - > bool
Disconnect receiver from sender for signal.
Parameters
| Name | Type | Description |
|---|---|---|
| receiver | Callable = null | The registered receiver to remove. |
| sender | Any = null | The sender associated with the registration. |
| weak | bool = null | Deprecated; has no effect on disconnection logic. |
| dispatch_uid | Hashable = null | The unique identifier used during connection to locate the receiver. |
Returns
| Type | Description |
|---|---|
bool | True if a receiver was successfully disconnected, False otherwise. |
has_listeners()
@classmethod
def has_listeners(
sender: Any = null
) - > bool
Checks if there are any active receivers registered for the specified sender.
Parameters
| Name | Type | Description |
|---|---|---|
| sender | Any = null | The sender object to check for listeners. |
Returns
| Type | Description |
|---|---|
bool | True if at least one live receiver is connected, False otherwise. |
send()
@classmethod
def send(
sender: Any,
**named: Any
) - > list
Send signal from sender to all connected receivers.
Parameters
| Name | Type | Description |
|---|---|---|
| sender | Any | The object initiating the signal. |
| **named | Any | Arbitrary keyword arguments passed directly to the receivers. |
Returns
| Type | Description |
|---|---|
list | A list of tuple pairs: [(receiver, response), ... ] where response may be an Exception. |