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

Function _task_get_stack

Lib/asyncio/base_tasks.py:34–66  ·  view source on GitHub ↗
(task, limit)

Source from the content-addressed store, hash-verified

32
33
34def _task_get_stack(task, limit):
35 frames = []
36 if hasattr(task._coro, 'cr_frame'):
37 # case 1: 'async def' coroutines
38 f = task._coro.cr_frame
39 elif hasattr(task._coro, 'gi_frame'):
40 # case 2: legacy coroutines
41 f = task._coro.gi_frame
42 elif hasattr(task._coro, 'ag_frame'):
43 # case 3: async generators
44 f = task._coro.ag_frame
45 else:
46 # case 4: unknown objects
47 f = None
48 if f is not None:
49 while f is not None:
50 if limit is not None:
51 if limit <= 0:
52 break
53 limit -= 1
54 frames.append(f)
55 f = f.f_back
56 frames.reverse()
57 elif task._exception is not None:
58 tb = task._exception.__traceback__
59 while tb is not None:
60 if limit is not None:
61 if limit <= 0:
62 break
63 limit -= 1
64 frames.append(tb.tb_frame)
65 tb = tb.tb_next
66 return frames
67
68
69def _task_print_stack(task, limit, file):

Callers

nothing calls this directly

Calls 2

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…