I’d like to propose a feature in some aspects similar to the TaskGroup, hence the working name.
Let’s have a coroutine t10 with a timeout of 10 seconds and t30 with a timeout of 30 seconds. Let’s assume those timeouts are reasonable values and both coroutines need much less time under usual circumstances.
When running both as two concurrent tasks with their respective timeouts, it can happen that t30 takes say 20 seconds to complete, but t10 needs more retrying. Everything is fine for t30, but t10 gets cancelled after 10 seconds even if there was room to let it run 10 seconds longer “for free” and thus increase its chances to succeed.
The idea is simple: Allow a longer timeout if another task in the group is running and didn’t reach its timeout limit yet. Example usage:
async with asyncio.TimeoutGroup() as tog:
tog.create_task(t10(), timeout=10) # timeout - new mandatory parameter
tog.create_task(t30(), timeout=30)
Some of you will find the gain too small and will propose e.g. to run everyting with the longest timeout of all timeouts. I was thinking about it, but decided to post.