-
Notifications
You must be signed in to change notification settings - Fork 817
Expand file tree
/
Copy path__init__.py
More file actions
30 lines (21 loc) · 848 Bytes
/
__init__.py
File metadata and controls
30 lines (21 loc) · 848 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
"""Utilities for async operations."""
from collections.abc import Awaitable, Callable
from ._task_group import _TaskGroup
from ._task_pool import _TaskPool
__all__ = ["_TaskGroup", "_TaskPool"]
async def stop_all(*funcs: Callable[..., Awaitable[None]]) -> None:
"""Call all stops in sequence and aggregate errors.
A failure in one stop call will not block subsequent stop calls.
Args:
funcs: Stop functions to call in sequence.
Raises:
RuntimeError: If any stop function raises an exception.
"""
exceptions = []
for func in funcs:
try:
await func()
except Exception as exception:
exceptions.append({"func_name": func.__name__, "exception": repr(exception)})
if exceptions:
raise RuntimeError(f"exceptions={exceptions} | failed stop sequence")