EventSlotWeakRef

class pynetevents.EventSlotWeakRef(name=None, propagate_exceptions=None, allow_duplicate_listeners=None)

Bases: _EventSlotBase

A slot to which callbacks can be attached and fired; += and -= use weak references for listeners.

__call__(*args, **kwds)

Invoke the event slot, calling all listeners with the passed args.

Return type:

None

__getitem__(index)

Get a listener by index.

Return type:

Callable[..., Any]

__iadd__(listener)

Adds a listener, internally calling unsubscribe_weak() (used by the ‘+=’ operator).

Return type:

EventSlot

__init__(name=None, propagate_exceptions=None, allow_duplicate_listeners=None)

Create a Slot that stores, invokes, and manages event callbacks registered on itself.

Parameters:
  • name (Optional[str], optional) – The internal name of the event slot. Typically set automatically by the descriptor when bound to a class attribute.

  • propagate_exceptions (Optional[bool], optional) – If True, exceptions raised by event listeners are propagated to the caller. If False, exceptions are caught and suppressed.

  • allow_duplicate_listeners (Optional[bool], optional) – If True, the same listener function can be added multiple times to the same event. If False, duplicate listeners raise an exception.

  • use_weakref_slot (Optional[bool], optional) – If True, event listeners are stored as weak references if possible, allowing the classes that the listeners belong to to be garbage collected.

If arguments are omitted the following defaults are used propagate_exceptions: True, allow_duplicate_listeners: False

__isub__(listener)

Removes a listener, internally calling subscribe_weak() (used by the ‘-=’ operator).

Return type:

EventSlot

__iter__()

Return an iterator over the listeners attached to the event slot.

Return type:

Iterator[Callable[..., Any]]

__len__()

Return the number of listeners attached to the event slot.

Return type:

int

invoke(*args, **kwargs)

Invoke all listeners passing the given args and kwargs. Synchronous listeners are called directly, while asynchronous listeners are scheduled (fire and forget).

Return type:

None

async invoke_async(*args, **kwargs)

Invoke all listeners passing the given args and kwargs, awaiting coroutine functions and calling normal functions synchronously.

Return type:

None

subscribe(listener)

Add a listener to the event slot.

Return type:

None

subscribe_weak(listener)

Add a listener to the event slot using a weak reference if possible.

Return type:

None

unsubscribe(listener)

Remove a listener from the event slot.

Return type:

None

unsubscribe_weak(listener)

Remove a listener from the event slot that was possibly added using a weak reference.

Return type:

None