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

gh-104144: Optimize gather to finish eagerly when all futures complete eagerly#104138

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletionLib/asyncio/tasks.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -813,6 +813,7 @@ def _done_callback(fut):
children = []
nfuts = 0
nfinished = 0
done_futs = []
loop = None
outer = None # bpo-46672
for arg in coros_or_futures:
Expand All@@ -829,7 +830,10 @@ def _done_callback(fut):

nfuts += 1
arg_to_fut[arg] = fut
fut.add_done_callback(_done_callback)
if fut.done():
done_futs.append(fut)
else:
fut.add_done_callback(_done_callback)

else:
# There's a duplicate Future object in coros_or_futures.
Expand All@@ -838,6 +842,13 @@ def _done_callback(fut):
children.append(fut)

outer = _GatheringFuture(children, loop=loop)
# Run done callbacks after GatheringFuture created so any post-processing
# can be performed at this point
# optimization: in the special case that *all* futures finished eagerly,
# this will effectively complete the gather eagerly, with the last
# callback setting the result (or exception) on outer before returning it
for fut in done_futs:
_done_callback(fut)
return outer


Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
Optimize :func:`asyncio.gather` when using :func:`asyncio.eager_task_factory`
to complete eagerly if all fututres completed eagerly.
Avoid scheduling done callbacks for fututres that complete eagerly.

[8]ページ先頭

©2009-2025 Movatter.jp