aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/asyncio/taskgroups.py
diff options
context:
space:
mode:
authorThomas Grainger <tagrain@gmail.com>2025-01-20 17:13:01 +0000
committerGitHub <noreply@github.com>2025-01-20 17:13:01 +0000
commited6934e71e55d398df8263f4697f58e4a3815f69 (patch)
treef191233d9f377ddc60189736fdfe469832206b8c /Lib/asyncio/taskgroups.py
parentab61d3f4303d14a413bc9ae6557c730ffdf7579e (diff)
downloadcpython-ed6934e71e55d398df8263f4697f58e4a3815f69.tar.gz
cpython-ed6934e71e55d398df8263f4697f58e4a3815f69.zip
gh-128588: gh-128550: remove eager tasks optimization that missed and introduced incorrect cancellations (#129063)
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
Diffstat (limited to 'Lib/asyncio/taskgroups.py')
-rw-r--r--Lib/asyncio/taskgroups.py12
1 files changed, 5 insertions, 7 deletions
diff --git a/Lib/asyncio/taskgroups.py b/Lib/asyncio/taskgroups.py
index 8af199d6dcc..8fda6c8d55e 100644
--- a/Lib/asyncio/taskgroups.py
+++ b/Lib/asyncio/taskgroups.py
@@ -197,14 +197,12 @@ class TaskGroup:
else:
task = self._loop.create_task(coro, name=name, context=context)
- # optimization: Immediately call the done callback if the task is
+ # Always schedule the done callback even if the task is
# already done (e.g. if the coro was able to complete eagerly),
- # and skip scheduling a done callback
- if task.done():
- self._on_task_done(task)
- else:
- self._tasks.add(task)
- task.add_done_callback(self._on_task_done)
+ # otherwise if the task completes with an exception then it will cancel
+ # the current task too early. gh-128550, gh-128588
+ self._tasks.add(task)
+ task.add_done_callback(self._on_task_done)
try:
return task
finally: