Attributes#
| Attribute | Type | Description |
|---|---|---|
aborted | = False |
Functions#
__init__#
__init__() -> Nonedef __init__(self) -> None:
self.aborted = False
self._listeners: list[Callable[[], object]] = []
self._lock = threading.Lock()add_listener#
add_listener(listener) -> Callable[[], object]Run listener on abort (now, if aborted already); returns a
function that removes it.
| Parameter | Type | Description |
|---|---|---|
listener | Callable[[], object] |
Returns Callable[[], object]
def add_listener(self, listener: Callable[[], object]) -> Callable[[], object]:
"""Run ``listener`` on abort (now, if aborted already); returns a
function that removes it."""
with self._lock:
if not self.aborted:
self._listeners.append(listener)
return lambda: self._remove(listener)
listener()
return _noop