Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

GH-91048: Add utils for printing the call stack for asyncio tasks #133284

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 33 commits into from
May 4, 2025
Merged
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
b11469a
GH-91048: Add utils for printing the call stack for asyncio tasks
pablogsal May 1, 2025
7f800e8
Maybe
pablogsal May 2, 2025
c5e4efe
Maybe
pablogsal May 2, 2025
1c982b1
Maybe
pablogsal May 2, 2025
2d94cde
fix configure
pablogsal May 2, 2025
0a9a496
fix configure
pablogsal May 2, 2025
db47ff3
fix configure
mgmacias95 May 2, 2025
6f8bd4c
some tests + fixes
mgmacias95 May 2, 2025
152b3d7
improve tests
mgmacias95 May 2, 2025
955ef27
dsf
pablogsal May 2, 2025
65aee3c
dsf
pablogsal May 2, 2025
51e689e
test fixes
pablogsal May 3, 2025
1d27348
test fixes
pablogsal May 3, 2025
1d1b0e9
test fixes
pablogsal May 3, 2025
edad4d1
test fixes
pablogsal May 3, 2025
199589c
Fix free threading offsets
pablogsal May 3, 2025
9e87032
Fix free threading offsets AGAIN
pablogsal May 3, 2025
69e9221
Debugging
pablogsal May 3, 2025
b6cb609
More tests
pablogsal May 3, 2025
2dd3452
Add news entry
pablogsal May 3, 2025
a84a171
Doc fixes
pablogsal May 3, 2025
0f75edc
Fix doc build
ambv May 3, 2025
c3a6bcb
Add Yury
ambv May 3, 2025
5e1cb87
fix: Show independent tasks in the table
mgmacias95 May 3, 2025
d92b520
Merge pull request #101 from mgmacias95/GH-91048-tasks
pablogsal May 3, 2025
af6a8bf
Temporarily skip test_async_global_awaited_by on free-threading
ambv May 3, 2025
8db5dbe
Drop the `tools`. It's cleaner.
ambv May 3, 2025
6f8aa6b
Satisfy the linting gods
ambv May 3, 2025
8d566c6
chore: Refactor
mgmacias95 May 4, 2025
977c15a
Merge pull request #103 from mgmacias95/GH-91048-tasks
pablogsal May 4, 2025
9dbe00d
Doc fixes
pablogsal May 4, 2025
c56782b
Type fixes
pablogsal May 4, 2025
293337f
Type fixes
pablogsal May 4, 2025
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
Prev Previous commit
Next Next commit
chore: Refactor
  • Loading branch information
mgmacias95 committed May 4, 2025
commit 8d566c6bc915578e98f44196fa3b4d1753b225a1
16 changes: 5 additions & 11 deletions 16 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
Morty Proxy This is a proxified and sanitized view of the page, visit original site.