summaryrefslogtreecommitdiffstats
path: root/Lib/asyncio/taskgroups.py
diff options
context:
space:
mode:
authorJason Zhang <yurenzhang2017@gmail.com>2024-03-06 20:20:26 (GMT)
committerGitHub <noreply@github.com>2024-03-06 20:20:26 (GMT)
commitce0ae1d784871085059a415aa589d9bd16ea8301 (patch)
treeec905cf72732077f8491602fb336b13aea967ae8 /Lib/asyncio/taskgroups.py
parent7114cf20c015b99123b32c1ba4f5475b7a6c3a13 (diff)
downloadcpython-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.py3
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)