Skip to main content

Signal

Create new signal.

Attributes

AttributeTypeDescription
receiversdict = NoneHolds a dictionary of {receiverkey (id): weakref(receiver)} mappings.
providing_argssetA set of the arguments this signal can pass along in a send call.
lockthreading.LockA threading lock used to ensure thread-safe access when connecting, disconnecting, or clearing receivers.
use_cachingboolEnable receiver cache to improve performance by storing receivers for distinct senders.
namestrName of signal, used for debugging purposes.
sender_receivers_cachedictA 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

NameTypeDescription
providing_argsList = NoneA list of the arguments this signal can pass along in a send call.
use_cachingbool = FalseEnable receiver cache to improve performance for repeated sends.
namestr = NoneName of the signal, used for debugging purposes.

Methods


connect()

@classmethod
def connect(
*args: Any,
**kwargs: Any
) - > Callable

Connect receiver to sender for signal.

Parameters

NameTypeDescription
*argsAnyPositional arguments, typically the receiver function.
**kwargsAnyKeyword arguments including sender, weak, dispatch_uid, and retry.

Returns

TypeDescription
CallableThe 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

NameTypeDescription
receiverCallable = nullThe registered receiver to remove.
senderAny = nullThe sender associated with the registration.
weakbool = nullDeprecated; has no effect on disconnection logic.
dispatch_uidHashable = nullThe unique identifier used during connection to locate the receiver.

Returns

TypeDescription
boolTrue 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

NameTypeDescription
senderAny = nullThe sender object to check for listeners.

Returns

TypeDescription
boolTrue 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

NameTypeDescription
senderAnyThe object initiating the signal.
**namedAnyArbitrary keyword arguments passed directly to the receivers.

Returns

TypeDescription
listA list of tuple pairs: [(receiver, response), ... ] where response may be an Exception.