Skip to content

Commit c779f23

Browse files
gh-134861: revert "Add CSV and BSV output formats to asyncio ps" (#138187)
This reverts commit ee72c95 and 470cbe9
1 parent 025a213 commit c779f23

File tree

3 files changed

+12
-59
lines changed

3 files changed

+12
-59
lines changed

Lib/asyncio/__main__.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import argparse
22
import ast
33
import asyncio
4+
import asyncio.tools
45
import concurrent.futures
56
import contextvars
67
import inspect
@@ -10,9 +11,6 @@
1011
import threading
1112
import types
1213
import warnings
13-
from asyncio.tools import (TaskTableOutputFormat,
14-
display_awaited_by_tasks_table,
15-
display_awaited_by_tasks_tree)
1614

1715
from _colorize import get_theme
1816
from _pyrepl.console import InteractiveColoredConsole
@@ -155,22 +153,17 @@ def interrupt(self) -> None:
155153
"ps", help="Display a table of all pending tasks in a process"
156154
)
157155
ps.add_argument("pid", type=int, help="Process ID to inspect")
158-
formats = [fmt.value for fmt in TaskTableOutputFormat]
159-
formats_to_show = [fmt for fmt in formats
160-
if fmt != TaskTableOutputFormat.bsv.value]
161-
ps.add_argument("--format", choices=formats, default="table",
162-
metavar=f"{{{','.join(formats_to_show)}}}")
163156
pstree = subparsers.add_parser(
164157
"pstree", help="Display a tree of all pending tasks in a process"
165158
)
166159
pstree.add_argument("pid", type=int, help="Process ID to inspect")
167160
args = parser.parse_args()
168161
match args.command:
169162
case "ps":
170-
display_awaited_by_tasks_table(args.pid, format=args.format)
163+
asyncio.tools.display_awaited_by_tasks_table(args.pid)
171164
sys.exit(0)
172165
case "pstree":
173-
display_awaited_by_tasks_tree(args.pid)
166+
asyncio.tools.display_awaited_by_tasks_tree(args.pid)
174167
sys.exit(0)
175168
case None:
176169
pass # continue to the interactive shell

Lib/asyncio/tools.py

Lines changed: 9 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
"""Tools to analyze tasks running in asyncio programs."""
22

3-
from collections import defaultdict
4-
import csv
3+
from collections import defaultdict, namedtuple
54
from itertools import count
6-
from enum import Enum, StrEnum, auto
5+
from enum import Enum
76
import sys
87
from _remote_debugging import RemoteUnwinder, FrameInfo
98

@@ -233,56 +232,18 @@ def _get_awaited_by_tasks(pid: int) -> list:
233232
sys.exit(1)
234233

235234

236-
class TaskTableOutputFormat(StrEnum):
237-
table = auto()
238-
csv = auto()
239-
bsv = auto()
240-
# 🍌SV is not just a format. It's a lifestyle. A philosophy.
241-
# https://www.youtube.com/watch?v=RrsVi1P6n0w
242-
243-
244-
def display_awaited_by_tasks_table(pid, *, format=TaskTableOutputFormat.table):
235+
def display_awaited_by_tasks_table(pid: int) -> None:
245236
"""Build and print a table of all pending tasks under `pid`."""
246237

247238
tasks = _get_awaited_by_tasks(pid)
248239
table = build_task_table(tasks)
249-
format = TaskTableOutputFormat(format)
250-
if format == TaskTableOutputFormat.table:
251-
_display_awaited_by_tasks_table(table)
252-
else:
253-
_display_awaited_by_tasks_csv(table, format=format)
254-
255-
256-
_row_header = ('tid', 'task id', 'task name', 'coroutine stack',
257-
'awaiter chain', 'awaiter name', 'awaiter id')
258-
259-
260-
def _display_awaited_by_tasks_table(table):
261-
"""Print the table in a simple tabular format."""
262-
print(_fmt_table_row(*_row_header))
263-
print('-' * 180)
240+
# Print the table in a simple tabular format
241+
print(
242+
f"{'tid':<10} {'task id':<20} {'task name':<20} {'coroutine stack':<50} {'awaiter chain':<50} {'awaiter name':<15} {'awaiter id':<15}"
243+
)
244+
print("-" * 180)
264245
for row in table:
265-
print(_fmt_table_row(*row))
266-
267-
268-
def _fmt_table_row(tid, task_id, task_name, coro_stack,
269-
awaiter_chain, awaiter_name, awaiter_id):
270-
# Format a single row for the table format
271-
return (f'{tid:<10} {task_id:<20} {task_name:<20} {coro_stack:<50} '
272-
f'{awaiter_chain:<50} {awaiter_name:<15} {awaiter_id:<15}')
273-
274-
275-
def _display_awaited_by_tasks_csv(table, *, format):
276-
"""Print the table in CSV format"""
277-
if format == TaskTableOutputFormat.csv:
278-
delimiter = ','
279-
elif format == TaskTableOutputFormat.bsv:
280-
delimiter = '\N{BANANA}'
281-
else:
282-
raise ValueError(f"Unknown output format: {format}")
283-
csv_writer = csv.writer(sys.stdout, delimiter=delimiter)
284-
csv_writer.writerow(_row_header)
285-
csv_writer.writerows(table)
246+
print(f"{row[0]:<10} {row[1]:<20} {row[2]:<20} {row[3]:<50} {row[4]:<50} {row[5]:<15} {row[6]:<15}")
286247

287248

288249
def display_awaited_by_tasks_tree(pid: int) -> None:

Misc/NEWS.d/next/Library/2025-05-29-19-00-37.gh-issue-134861.y2-fu-.rst

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)