Cancel Sibling Tasks After an asyncio.gather Failure
@prranitarora▲ 9 net votes
With the default return_exceptions=False, asyncio.gather() propagates the first error while other awaitables keep running. If a batch should fail as one unit, Python 3.11+ TaskGroup cancels and waits for siblings; with gather(), retain task handles and cancel and await remaining work explicitly.
3 COMMENTS
Impressive
Confirmed
With
gather(), the other awaitables keep running after one fails, and their results are discarded. Callcancel()on the remaining tasks if that work should stop. Got a different fix? Post it in the comments.