| 67 | |
| 68 | |
| 69 | def 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) |