diff options
author | Jason Zhang <yurenzhang2017@gmail.com> | 2024-03-06 20:20:26 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-06 20:20:26 (GMT) |
commit | ce0ae1d784871085059a415aa589d9bd16ea8301 (patch) | |
tree | ec905cf72732077f8491602fb336b13aea967ae8 /Lib/asyncio/taskgroups.py | |
parent | 7114cf20c015b99123b32c1ba4f5475b7a6c3a13 (diff) | |
download | cpython-ce0ae1d784871085059a415aa589d9bd16ea8301.zip cpython-ce0ae1d784871085059a415aa589d9bd16ea8301.tar.gz cpython-ce0ae1d784871085059a415aa589d9bd16ea8301.tar.bz2 |
gh-115957: Close coroutine if TaskGroup.create_task() raises an error (#116009)
Diffstat (limited to 'Lib/asyncio/taskgroups.py')
-rw-r--r-- | Lib/asyncio/taskgroups.py | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/Lib/asyncio/taskgroups.py b/Lib/asyncio/taskgroups.py index f322b1f..57f0123 100644 --- a/Lib/asyncio/taskgroups.py +++ b/Lib/asyncio/taskgroups.py @@ -154,10 +154,13 @@ class TaskGroup: Similar to `asyncio.create_task`. """ if not self._entered: + coro.close() raise RuntimeError(f"TaskGroup {self!r} has not been entered") if self._exiting and not self._tasks: + coro.close() raise RuntimeError(f"TaskGroup {self!r} is finished") if self._aborting: + coro.close() raise RuntimeError(f"TaskGroup {self!r} is shutting down") if context is None: task = self._loop.create_task(coro, name=name) |