diff options
author | Łukasz Langa <lukasz@langa.pl> | 2025-05-06 01:07:33 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-05-05 23:07:33 +0000 |
commit | 60cdd800d95517f4395210f38709de9e8f11ea90 (patch) | |
tree | 1246d626bcca2efc0ee20557f26a914f35524220 /Lib/asyncio/tools.py | |
parent | cae660d6dc0d7ba3f66970ef2f2faf1b93869e91 (diff) | |
download | cpython-60cdd800d95517f4395210f38709de9e8f11ea90.tar.gz cpython-60cdd800d95517f4395210f38709de9e8f11ea90.zip |
gh-91048: Add filename:line_no information to `asyncio pstree` (#133478)
Diffstat (limited to 'Lib/asyncio/tools.py')
-rw-r--r-- | Lib/asyncio/tools.py | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/Lib/asyncio/tools.py b/Lib/asyncio/tools.py index dde755e3796..bf1cb5e64cb 100644 --- a/Lib/asyncio/tools.py +++ b/Lib/asyncio/tools.py @@ -21,13 +21,21 @@ class CycleFoundException(Exception): # ─── indexing helpers ─────────────────────────────────────────── +def _format_stack_entry(elem: tuple[str, str, int] | str) -> str: + if isinstance(elem, tuple): + fqname, path, line_no = elem + return f"{fqname} {path}:{line_no}" + + return elem + + def _index(result): id2name, awaits = {}, [] for _thr_id, tasks in result: for tid, tname, awaited in tasks: id2name[tid] = tname for stack, parent_id in awaited: - stack = [elem[0] if isinstance(elem, tuple) else elem for elem in stack] + stack = [_format_stack_entry(elem) for elem in stack] awaits.append((parent_id, stack, tid)) return id2name, awaits @@ -106,7 +114,7 @@ def _find_cycles(graph): # ─── PRINT TREE FUNCTION ─────────────────────────────────────── def build_async_tree(result, task_emoji="(T)", cor_emoji=""): """ - Build a list of strings for pretty-print a async call tree. + Build a list of strings for pretty-print an async call tree. The call tree is produced by `get_all_async_stacks()`, prefixing tasks with `task_emoji` and coroutine frames with `cor_emoji`. @@ -169,7 +177,7 @@ def build_task_table(result): return table def _print_cycle_exception(exception: CycleFoundException): - print("ERROR: await-graph contains cycles – cannot print a tree!", file=sys.stderr) + print("ERROR: await-graph contains cycles - cannot print a tree!", file=sys.stderr) print("", file=sys.stderr) for c in exception.cycles: inames = " → ".join(exception.id2name.get(tid, hex(tid)) for tid in c) |