Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit52d8f36

Browse files
itamarocarljm
andauthored
gh-104144: Skip scheduling a done callback if a TaskGroup task completes eagerly (#104140)
Co-authored-by: Carl Meyer <carl@oddbird.net>
1 parentf3e7eb4 commit52d8f36

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

‎Lib/asyncio/taskgroups.py‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,14 @@ def create_task(self, coro, *, name=None, context=None):
164164
else:
165165
task=self._loop.create_task(coro,context=context)
166166
tasks._set_task_name(task,name)
167-
task.add_done_callback(self._on_task_done)
168-
self._tasks.add(task)
167+
# optimization: Immediately call the done callback if the task is
168+
# already done (e.g. if the coro was able to complete eagerly),
169+
# and skip scheduling a done callback
170+
iftask.done():
171+
self._on_task_done(task)
172+
else:
173+
self._tasks.add(task)
174+
task.add_done_callback(self._on_task_done)
169175
returntask
170176

171177
# Since Python 3.8 Tasks propagate all exceptions correctly,
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Optimize:class:`asyncio.TaskGroup` when using:func:`asyncio.eager_task_factory`. Skip scheduling done callbacks when all tasks finish without blocking.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp