MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / gather

Function gather

tools/python-3.11.9-amd64/Lib/asyncio/tasks.py:728–848  ·  view source on GitHub ↗

Return a future aggregating results from the given coroutines/futures. Coroutines will be wrapped in a future and scheduled in the event loop. They will not necessarily be scheduled in the same order as passed in. All futures must share the same event loop. If all the tasks

(*coros_or_futures, return_exceptions=False)

Source from the content-addressed store, hash-verified

726
727
728def gather(*coros_or_futures, return_exceptions=False):
729 """Return a future aggregating results from the given coroutines/futures.
730
731 Coroutines will be wrapped in a future and scheduled in the event
732 loop. They will not necessarily be scheduled in the same order as
733 passed in.
734
735 All futures must share the same event loop. If all the tasks are
736 done successfully, the returned future's result is the list of
737 results (in the order of the original sequence, not necessarily
738 the order of results arrival). If *return_exceptions* is True,
739 exceptions in the tasks are treated the same as successful
740 results, and gathered in the result list; otherwise, the first
741 raised exception will be immediately propagated to the returned
742 future.
743
744 Cancellation: if the outer Future is cancelled, all children (that
745 have not completed yet) are also cancelled. If any child is
746 cancelled, this is treated as if it raised CancelledError --
747 the outer Future is *not* cancelled in this case. (This is to
748 prevent the cancellation of one child to cause other children to
749 be cancelled.)
750
751 If *return_exceptions* is False, cancelling gather() after it
752 has been marked done won't cancel any submitted awaitables.
753 For instance, gather can be marked done after propagating an
754 exception to the caller, therefore, calling ``gather.cancel()``
755 after catching an exception (raised by one of the awaitables) from
756 gather won't cancel any other awaitables.
757 """
758 if not coros_or_futures:
759 loop = events._get_event_loop()
760 outer = loop.create_future()
761 outer.set_result([])
762 return outer
763
764 def _done_callback(fut):
765 nonlocal nfinished
766 nfinished += 1
767
768 if outer is None or outer.done():
769 if not fut.cancelled():
770 # Mark exception retrieved.
771 fut.exception()
772 return
773
774 if not return_exceptions:
775 if fut.cancelled():
776 # Check if 'fut' is cancelled first, as
777 # 'fut.exception()' will *raise* a CancelledError
778 # instead of returning it.
779 exc = fut._make_cancelled_error()
780 outer.set_exception(exc)
781 return
782 else:
783 exc = fut.exception()
784 if exc is not None:
785 outer.set_exception(exc)

Callers

nothing calls this directly

Calls 7

_ensure_futureFunction · 0.85
_GatheringFutureClass · 0.85
_get_loopMethod · 0.80
create_futureMethod · 0.45
set_resultMethod · 0.45
add_done_callbackMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected