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

Function walk

Lib/test/test_asyncio/test_graph.py:13–39  ·  view source on GitHub ↗
(s)

Source from the content-addressed store, hash-verified

11def capture_test_stack(*, fut=None, depth=1):
12
13 def walk(s):
14 ret = [
15 (f"T<{n}>" if '-' not in (n := s.future.get_name()) else 'T<anon>')
16 if isinstance(s.future, asyncio.Task) else 'F'
17 ]
18
19 ret.append(
20 [
21 (
22 f"s {entry.frame.f_code.co_name}"
23 if entry.frame.f_generator is None else
24 (
25 f"a {entry.frame.f_generator.cr_code.co_name}"
26 if hasattr(entry.frame.f_generator, 'cr_code') else
27 f"ag {entry.frame.f_generator.ag_code.co_name}"
28 )
29 ) for entry in s.call_stack
30 ]
31 )
32
33 ret.append(
34 sorted([
35 walk(ab) for ab in s.awaited_by
36 ], key=lambda entry: entry[0])
37 )
38
39 return ret
40
41 buf = io.StringIO()
42 asyncio.print_call_graph(fut, file=buf, depth=depth+1)

Callers 1

capture_test_stackFunction · 0.70

Calls 2

get_nameMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…