What is the difference between asyncio.gather() and asyncio.TaskGroup (Python 3.11+)?

Python Professional Hard

Python Professional — Hard

What is the difference between asyncio.gather() and asyncio.TaskGroup (Python 3.11+)?

Key points

  • TaskGroup cancels all sibling tasks on exception, while gather() only propagates the first exception.
  • TaskGroup collects multiple exceptions in an ExceptionGroup.
  • gather() returns all results by default.

Ready to go further?

Related questions