Commit 7f60548
authored
`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 PR introduces a new `PersistentTaskGroup` class, 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.
The `ServiceBase` class is updated to use a `PersistentTaskGroup`
underneath, and it is simplified for single-task services by making the
service driven by a single `main` task, which can use the new group to
monitor sub-tasks and act accordingly.
This is part of #27 and #9.
File tree
7 files changed
+1026
-200
lines changed- src/frequenz/core/asyncio
- tests/asyncio
7 files changed
+1026
-200
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 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 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
0 commit comments