Skip to content

Commit e763949

Browse files
committed
Add a PersistentTaskGroup class
`asyncio.TaskGroup` is a very convenient construct when using parallelization for doing calculations for example, where the results for all the tasks need to be merged together to produce a final result. In this case if one of the tasks fails, it makes sense to cancel the others and abort as soon as possible, as any further calculations would be thrown away. This class is intended to help managing a group of tasks that should persist even if other tasks in the group fail, usually by either only discarding the failed task or by restarting it somehow. Signed-off-by: Leandro Lucarella <[email protected]>
1 parent 064a707 commit e763949

File tree

3 files changed

+783
-0
lines changed

3 files changed

+783
-0
lines changed

src/frequenz/core/asyncio/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
1111
- [cancel_and_await][frequenz.core.asyncio.cancel_and_await]: A function that cancels a
1212
task and waits for it to finish, handling `CancelledError` exceptions.
13+
- [PersistentTaskGroup][frequenz.core.asyncio.PersistentTaskGroup]: An alternative to
14+
[`asyncio.TaskGroup`][] to manage tasks that run until explicitly stopped.
1315
- [Service][frequenz.core.asyncio.Service]: An interface for services running in the
1416
background.
1517
- [ServiceBase][frequenz.core.asyncio.ServiceBase]: A base class for implementing
@@ -18,9 +20,11 @@
1820
"""
1921

2022
from ._service import Service, ServiceBase
23+
from ._task_group import PersistentTaskGroup
2124
from ._util import TaskCreator, TaskReturnT, cancel_and_await
2225

2326
__all__ = [
27+
"PersistentTaskGroup",
2428
"Service",
2529
"ServiceBase",
2630
"TaskCreator",

0 commit comments

Comments
 (0)