MCPcopy Index your code
hub / github.com/python/cpython / _done_callback

Function _done_callback

Lib/asyncio/tasks.py:810–866  ·  view source on GitHub ↗
(fut, cur_task=cur_task)

Source from the content-addressed store, hash-verified

808 cur_task = None
809
810 def _done_callback(fut, cur_task=cur_task):
811 nonlocal nfinished
812 nfinished += 1
813
814 if cur_task is not None:
815 futures.future_discard_from_awaited_by(fut, cur_task)
816
817 if outer is None or outer.done():
818 if not fut.cancelled():
819 # Mark exception retrieved.
820 fut.exception()
821 return
822
823 if not return_exceptions:
824 if fut.cancelled():
825 # Check if 'fut' is cancelled first, as
826 # 'fut.exception()' will *raise* a CancelledError
827 # instead of returning it.
828 exc = fut._make_cancelled_error()
829 outer.set_exception(exc)
830 return
831 else:
832 exc = fut.exception()
833 if exc is not None:
834 outer.set_exception(exc)
835 return
836
837 if nfinished == nfuts:
838 # All futures are done; create a list of results
839 # and set it to the 'outer' future.
840 results = []
841
842 for fut in children:
843 if fut.cancelled():
844 # Check if 'fut' is cancelled first, as 'fut.exception()'
845 # will *raise* a CancelledError instead of returning it.
846 # Also, since we're adding the exception return value
847 # to 'results' instead of raising it, don't bother
848 # setting __context__. This also lets us preserve
849 # calling '_make_cancelled_error()' at most once.
850 res = exceptions.CancelledError(
851 '' if fut._cancel_message is None else
852 fut._cancel_message)
853 else:
854 res = fut.exception()
855 if res is None:
856 res = fut.result()
857 results.append(res)
858
859 if outer._cancel_requested:
860 # If gather is being cancelled we must propagate the
861 # cancellation regardless of *return_exceptions* argument.
862 # See issue 32684.
863 exc = fut._make_cancelled_error()
864 outer.set_exception(exc)
865 else:
866 outer.set_result(results)
867

Callers 1

gatherFunction · 0.85

Calls 8

_make_cancelled_errorMethod · 0.80
doneMethod · 0.45
cancelledMethod · 0.45
exceptionMethod · 0.45
set_exceptionMethod · 0.45
resultMethod · 0.45
appendMethod · 0.45
set_resultMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…