mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
gh-115957: Close coroutine if TaskGroup.create_task() raises an error (#116009)
This commit is contained in:
parent
7114cf20c0
commit
ce0ae1d784
5 changed files with 42 additions and 16 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue