Skip to content
Merged
Changes from all commits
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
16 changes: 5 additions & 11 deletions Lib/asyncio/tools.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Tool to analyze tasks running in a asyncio script."""

from dataclasses import dataclass
from collections import defaultdict
from itertools import count
Expand Down Expand Up @@ -46,10 +48,6 @@ def _cor_node(parent_key, frame_name):
bucket[frame_name] = node_key
return node_key

# touch every task so it’s present even if it awaits nobody
for tid in id2name:
children[(NodeType.TASK, tid)]

# lay down parent ➜ …frames… ➜ child paths
for parent_id, stack, child_id in awaits:
cur = (NodeType.TASK, parent_id)
Expand All @@ -69,7 +67,6 @@ def _roots(id2label, children):
# ─── detect cycles in the task-to-task graph ───────────────────────
def _task_graph(awaits):
"""Return {parent_task_id: {child_task_id, …}, …}."""
from collections import defaultdict
g = defaultdict(set)
for parent_id, _stack, child_id in awaits:
g[parent_id].add(child_id)
Expand Down Expand Up @@ -106,7 +103,7 @@ def dfs(v):


# ─── PRINT TREE FUNCTION ───────────────────────────────────────
def build_async_tree(result, task_emoji="(T)", cor_emoji="", printer=print):
def build_async_tree(result, task_emoji="(T)", cor_emoji=""):
"""
Build a list of strings for pretty-print a async call tree.

Expand Down Expand Up @@ -134,10 +131,7 @@ def render(node, prefix="", last=True, buf=None):
render(kid, new_pref, i == len(kids) - 1, buf)
return buf

result = []
for r, root in enumerate(_roots(labels, children)):
result.append(render(root))
return result
return [render(root) for root in _roots(labels, children)]


def build_task_table(result):
Expand Down Expand Up @@ -209,7 +203,7 @@ def display_awaited_by_tasks_tree(pid: int) -> None:

tasks = _get_awaited_by_tasks(pid)
try:
result = print_async_tree(tasks)
result = build_async_tree(tasks)
except CycleFoundException as e:
_print_cycle_exception(e)
sys.exit(1)
Expand Down