Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add filename:line_no information to asyncio pstree
  • Loading branch information
ambv committed May 5, 2025
commit ab2b0c584145145ecdac2ff8e87778e0f6846a50
1 change: 1 addition & 0 deletions Lib/asyncio/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ def interrupt(self) -> None:
parser = argparse.ArgumentParser(
prog="python3 -m asyncio",
description="Interactive asyncio shell and CLI tools",
color=True,
Comment thread
ambv marked this conversation as resolved.
)
subparsers = parser.add_subparsers(help="sub-commands", dest="command")
ps = subparsers.add_parser(
Expand Down
10 changes: 9 additions & 1 deletion Lib/asyncio/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down