Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
16 changes: 14 additions & 2 deletions Lib/asyncio/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,7 @@ def _done_callback(fut):
nfinished = 0
loop = None
outer = None # bpo-46672
all_finished = True
Comment thread
itamaro marked this conversation as resolved.
Outdated
for arg in coros_or_futures:
if arg not in arg_to_fut:
fut = ensure_future(arg, loop=loop)
Expand All @@ -829,15 +830,26 @@ def _done_callback(fut):

nfuts += 1
arg_to_fut[arg] = fut
fut.add_done_callback(_done_callback)
if fut.done():
# call the callback immediately instead of scheduling it
_done_callback(fut)
else:
all_finished = False
Comment thread
itamaro marked this conversation as resolved.
Outdated
fut.add_done_callback(_done_callback)

else:
# There's a duplicate Future object in coros_or_futures.
fut = arg_to_fut[arg]

children.append(fut)

outer = _GatheringFuture(children, loop=loop)
if all_finished:
Comment thread
itamaro marked this conversation as resolved.
Outdated
# optimization: skip creating GatheringFuture if all children completed
# (e.g. when all coros are able to complete eagerly)
outer = futures.Future(loop=loop)
Comment thread
itamaro marked this conversation as resolved.
Outdated
outer.set_result([c.result for c in children])
Comment thread
itamaro marked this conversation as resolved.
Outdated
else:
outer = _GatheringFuture(children, loop=loop)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
outer = _GatheringFuture(children, loop=loop)
outer.__self_log_traceback = False
outer = _GatheringFuture(children, loop=loop)

return outer


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Optimize asyncio.gather when using eager tasks factory Skip creating
gathering future and scheduling done callbacks when all futures finish
without blocking - for up to 3x speedup
Comment thread
itamaro marked this conversation as resolved.
Outdated