achimnol / aiotools

Idiomatic asyncio utilties
https://aiotools.readthedocs.io
MIT License
153 stars 11 forks source link

Add shutdown timeout to PersistentTaskGroup #33

Open achimnol opened 2 years ago

achimnol commented 2 years ago

Currently PersistentTaskGroup immediately cancels all non-finished tasks upon shutdown. Let's add an option for configurable timeout here, so that the individual tasks may have chances to finish up before being cancelled.

achimnol commented 2 years ago

We could use two-phase cancellation: requesting cancellation after 1st timeout, cancel cancellation after 2nd timeout if it takes too long, with help of Task.uncancel() and cancellation scopes to be introduced in Python 3.11.

refs https://github.com/python/cpython/pull/31513