(
future: futures.Future,
*,
limit: int | None = None,
)
| 38 | |
| 39 | |
| 40 | def _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 | |
| 83 | def capture_call_graph( |
no test coverage detected
searching dependent graphs…