New research project: Cancel scopes and level cancellation on asyncio

  • All tasks (except for the root task which runs all other tasks) belong to task groups(create_task() creates tasks in the root task group)
  • If a task raises an exception, it propagates to the parent task
  • If the root task group receives an exception, the event loop is shut down and the exception is propagated to the caller of run()

These points are a non-starter. I’m in favor of making there be an event-loop scoped way of managing background tasks, but treating any exception from asyncio.create_task as something to shutdown the event loop isn’t practical, flies in the face of what users have directly asked for, and it’s highly opinionated in a way that conflicts with some existing valid code.

See this thread for some discussion about ways to scope create_task that don’t break existing intentional use with known possible failing: Pain point in asyncio: Potentially-failing tasks

1 Like