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
Changes from1 commit
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
PrevPrevious commit
NextNext commit
Modify implementation to eagerly call done callbacks at the end of th…
…e loop, after the GatheringFuture (outer) is created
  • Loading branch information
@itamaro
itamaro committedMay 5, 2023
commit9be6e519273e8ce3078e9f9e9e2c61bb292417c7
21 changes: 10 additions & 11 deletionsLib/asyncio/tasks.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -813,9 +813,9 @@ def _done_callback(fut):
children = []
nfuts = 0
nfinished = 0
done_futs = []
loop = None
outer = None # bpo-46672
all_finished = True
for arg in coros_or_futures:
if arg not in arg_to_fut:
fut = ensure_future(arg, loop=loop)
Expand All@@ -831,10 +831,8 @@ def _done_callback(fut):
nfuts += 1
arg_to_fut[arg] = fut
if fut.done():
# call the callback immediately instead of scheduling it
_done_callback(fut)
done_futs.append(fut)
else:
all_finished = False
fut.add_done_callback(_done_callback)

else:
Expand All@@ -843,13 +841,14 @@ def _done_callback(fut):

children.append(fut)

if all_finished:
# optimization: skip creating GatheringFuture if all children completed
# (e.g. when all coros are able to complete eagerly)
outer = futures.Future(loop=loop)
outer.set_result([c.result for c in children])
else:
outer = _GatheringFuture(children, loop=loop)
outer = _GatheringFuture(children, loop=loop)
# call the done callbacks for futures that finished eagerly, instead
# of scheduling the callbacks to be called later by the event loop
# 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

[8]ページ先頭

©2009-2025 Movatter.jp