[issue46843] PersistentTaskGroup API
Joongi Kim
report at bugs.python.org
Thu Feb 24 08:17:54 EST 2022
Joongi Kim <me at daybreaker.info> added the comment:
So I have more things in mind.
Basically PersistentTaskGroup resemble TaskGroup in that:
- It has the same "create_task()" method.
- It has an explicit "cancel()" or "shutdown()" method.
- Exiting of the context manager means that all tasks of it have either completed or cancelled.
TaskGroup is intended to be used for a short-lived set of tasks, while PersistentTaskGroup is intended for a long-running set of tasks though individual tasks may be short-lived. Thus, adding globally accessible monitoring facility for plain TaskGroup would not be that useful. In contrast, it is super-useful to have a monitoring feature in PersistentTaskGroup!
In aiomonitor, we can enumerate the currently running asyncio tasks by reading asyncio.Task.all_tasks(). This has saved my life several times when debugging real-world server applications. I think we can go further by having asyncio.PersistentTaskGroup.all_task_groups() which works in the same way. If we make different modules and libraries to use different persistent task groups, then we could keep track of their task statistics separately.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue46843>
_______________________________________
More information about the Python-bugs-list
mailing list