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

Function _build_graph_for_future

Lib/asyncio/graph.py:40–80  ·  view source on GitHub ↗
(
    future: futures.Future,
    *,
    limit: int | None = None,
)

Source from the content-addressed store, hash-verified

38
39
40def _build_graph_for_future(
41 future: futures.Future,
42 *,
43 limit: int | None = None,
44) -> FutureCallGraph:
45 if not isinstance(future, futures.Future):
46 raise TypeError(
47 f"{future!r} object does not appear to be compatible "
48 f"with asyncio.Future"
49 )
50
51 coro = None
52 if get_coro := getattr(future, 'get_coro', None):
53 coro = get_coro() if limit != 0 else None
54
55 st: list[FrameCallGraphEntry] = []
56 awaited_by: list[FutureCallGraph] = []
57
58 while coro is not None:
59 if hasattr(coro, 'cr_await'):
60 # A native coroutine or duck-type compatible iterator
61 st.append(FrameCallGraphEntry(coro.cr_frame))
62 coro = coro.cr_await
63 elif hasattr(coro, 'ag_await'):
64 # A native async generator or duck-type compatible iterator
65 st.append(FrameCallGraphEntry(coro.cr_frame))
66 coro = coro.ag_await
67 else:
68 break
69
70 if future._asyncio_awaited_by:
71 for parent in future._asyncio_awaited_by:
72 awaited_by.append(_build_graph_for_future(parent, limit=limit))
73
74 if limit is not None:
75 if limit > 0:
76 st = st[:limit]
77 elif limit < 0:
78 st = st[limit:]
79 st.reverse()
80 return FutureCallGraph(future, tuple(st), tuple(awaited_by))
81
82
83def capture_call_graph(

Callers 1

capture_call_graphFunction · 0.85

Calls 4

FrameCallGraphEntryClass · 0.85
FutureCallGraphClass · 0.85
appendMethod · 0.45
reverseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…