From 594c3699492bfb007650538726d953cbed55de04 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Thu, 30 Jun 2022 10:10:46 -0700 Subject: GH-94398: TaskGroup: Fail create_task() during shutdown (GH-94400) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Once the task group is shutting down, it should not be possible to create a new task. Here "shutting down" means `self._aborting` is set, indicating that at least one task has failed and we have cancelled all others. Co-authored-by: Ɓukasz Langa --- Lib/asyncio/taskgroups.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'Lib/asyncio/taskgroups.py') diff --git a/Lib/asyncio/taskgroups.py b/Lib/asyncio/taskgroups.py index 9e0610deed2..3ca65062efd 100644 --- a/Lib/asyncio/taskgroups.py +++ b/Lib/asyncio/taskgroups.py @@ -138,6 +138,8 @@ class TaskGroup: raise RuntimeError(f"TaskGroup {self!r} has not been entered") if self._exiting and not self._tasks: raise RuntimeError(f"TaskGroup {self!r} is finished") + if self._aborting: + raise RuntimeError(f"TaskGroup {self!r} is shutting down") if context is None: task = self._loop.create_task(coro) else: -- cgit v1.2.3