MCPcopy
hub / github.com/mitmproxy/mitmproxy / print_refs

Function print_refs

test/helper_tools/hunt_memory_leaks.py:69–94  ·  view source on GitHub ↗
(x, ignore: set, seen: set, depth: int = 0, max_depth: int = 10)

Source from the content-addressed store, hash-verified

67
68
69def print_refs(x, ignore: set, seen: set, depth: int = 0, max_depth: int = 10):
70 if id(x) in ignore:
71 return
72
73 if id(x) in seen:
74 print(
75 " " * depth
76 + "↖ "
77 + repr(str(x))[1:60]
78 + f" (\x1b[31mseen\x1b[0m: {id(x):x})"
79 )
80 return
81 else:
82 if depth == 0:
83 print("- " + repr(str(x))[1:60] + f" ({id(x):x})")
84 else:
85 print(" " * depth + "↖ " + repr(str(x))[1:60] + f" ({id(x):x})")
86 seen.add(id(x))
87
88 if depth == max_depth:
89 return
90
91 referrers = tuple(gc.get_referrers(x))
92 ignore.add(id(referrers))
93 for ref in referrers:
94 print_refs(ref, ignore, seen, depth + 1, max_depth)

Callers

nothing calls this directly

Calls 2

idFunction · 0.50
addMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…