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
Prev Previous commit
Next Next commit
Merge branch 'main' into feature/pending-tasks-BANANAS
# Conflicts:
#	Lib/asyncio/__main__.py
#	Lib/asyncio/tools.py
  • Loading branch information
AA-Turner committed Aug 6, 2025
commit 5291ed389b114e977c7593ddabab6ff7fc8a7448
7 changes: 3 additions & 4 deletions Lib/asyncio/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,9 @@ def interrupt(self) -> None:
"ps", help="Display a table of all pending tasks in a process"
)
ps.add_argument("pid", type=int, help="Process ID to inspect")
formats = [fmt.value for fmt in asyncio.tools.TaskTableOutputFormat]
big_secret = asyncio.tools.TaskTableOutputFormat.bsv.value
formats = [fmt.value for fmt in TaskTableOutputFormat]
formats_to_show = [
fmt for fmt in formats if fmt != big_secret
fmt for fmt in formats if fmt != TaskTableOutputFormat.bsv.value
]
formats_to_show_str = f"{{{','.join(formats_to_show)}}}"
ps.add_argument("--format", choices=formats, default="table",
Expand All @@ -170,7 +169,7 @@ def interrupt(self) -> None:
args = parser.parse_args()
match args.command:
case "ps":
asyncio.tools.display_awaited_by_tasks_table(args.pid, args.format)
display_awaited_by_tasks_table(args.pid, format=args.format)
sys.exit(0)
case "pstree":
display_awaited_by_tasks_tree(args.pid)
Expand Down
24 changes: 11 additions & 13 deletions Lib/asyncio/tools.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
"""Tools to analyze tasks running in asyncio programs."""

from collections import defaultdict, namedtuple
from collections import defaultdict
import csv
from itertools import count
from enum import Enum, StrEnum, auto
import sys
from _remote_debugging import RemoteUnwinder, FrameInfo


class NodeType(Enum):
COROUTINE = 1
TASK = 2
Expand Down Expand Up @@ -242,10 +241,7 @@ class TaskTableOutputFormat(StrEnum):
# https://www.youtube.com/watch?v=RrsVi1P6n0w


def display_awaited_by_tasks_table(
pid: int,
format: TaskTableOutputFormat | str = TaskTableOutputFormat.table
) -> None:
def display_awaited_by_tasks_table(pid, *, format=TaskTableOutputFormat.table):
"""Build and print a table of all pending tasks under `pid`."""

tasks = _get_awaited_by_tasks(pid)
Expand All @@ -254,15 +250,17 @@ def display_awaited_by_tasks_table(
if format == TaskTableOutputFormat.table:
_display_awaited_by_tasks_table(table)
else:
_display_awaited_by_tasks_csv(table, format)
_display_awaited_by_tasks_csv(table, format=format)


_row_header = ('tid', 'task id', 'task name', 'coroutine stack',
'awaiter chain', 'awaiter name', 'awaiter id')


def _display_awaited_by_tasks_table(table) -> None:
# Print the table in a simple tabular format
print(
f"{'tid':<10} {'task id':<20} {'task name':<20} {'coroutine stack':<50} {'awaiter chain':<50} {'awaiter name':<15} {'awaiter id':<15}"
)
print("-" * 180)
def _display_awaited_by_tasks_table(table):
"""Print the table in a simple tabular format."""
print(_fmt_table_row(*_row_header))
print('-' * 180)
for row in table:
print(_fmt_table_row(*row))

Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.