[issue46843] PersistentTaskGroup API

Joongi Kim report at bugs.python.org
Fri Feb 25 14:38:24 EST 2022


Joongi Kim <me at daybreaker.info> added the comment:

Short summary:

PersistentTaskGroup shares the followings from TaskGroup:
- It uses WeakSet to keep track of child tasks.
- After exiting the async context manager scope (or the shutdown procedure), it ensures that all tasks are complete or cancelled.

PersistentTaskGroup differs in that:
- It keeps running after all tasks successfully finish unless it is explicitly shutdown or the parent task is cancelled.
- It is one of the main use cases that shutdown() method is called separately.  The shutdown procedure may be triggered from different task contexts.
- It provides two-phase cancellation with a configurable grace period.
- It does not propagate unhandled exceptions and cancellations from child tasks to the outside of the task group and sibling tasks but calls a customizable fallback exception handler. -> This could be done without modifying TaskGroup.

The API looks similar to TaskGroup with minor modification.
The semantics of a PersistentTaskGroup more resembles a nested event loop, in that it has its own set of tasks, it keeps running until closed, and it has its own fallback exception handler.

Note that current aiotools implementation lacks many details, such as two-phase cancellation.  I'm going to implement more soon.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue46843>
_______________________________________


More information about the Python-bugs-list mailing list