Skip to content

Commit 1f00100

Browse files
Revert "gh-134861: Add CSV output format to python -m asyncio ps (#134862)"
This reverts commit 470cbe9.
1 parent 280d5e4 commit 1f00100

File tree

3 files changed

+12
-51
lines changed

3 files changed

+12
-51
lines changed

Lib/asyncio/__main__.py

Lines changed: 3 additions & 7 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,19 +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-
ps.add_argument("--format", choices=formats, default="table")
160156
pstree = subparsers.add_parser(
161157
"pstree", help="Display a tree of all pending tasks in a process"
162158
)
163159
pstree.add_argument("pid", type=int, help="Process ID to inspect")
164160
args = parser.parse_args()
165161
match args.command:
166162
case "ps":
167-
display_awaited_by_tasks_table(args.pid, format=args.format)
163+
asyncio.tools.display_awaited_by_tasks_table(args.pid)
168164
sys.exit(0)
169165
case "pstree":
170-
display_awaited_by_tasks_tree(args.pid)
166+
asyncio.tools.display_awaited_by_tasks_tree(args.pid)
171167
sys.exit(0)
172168
case None:
173169
pass # continue to the interactive shell

Lib/asyncio/tools.py

Lines changed: 9 additions & 43 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,51 +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-
240-
241-
def display_awaited_by_tasks_table(pid, *, format=TaskTableOutputFormat.table):
235+
def display_awaited_by_tasks_table(pid: int) -> None:
242236
"""Build and print a table of all pending tasks under `pid`."""
243237

244238
tasks = _get_awaited_by_tasks(pid)
245239
table = build_task_table(tasks)
246-
format = TaskTableOutputFormat(format)
247-
if format == TaskTableOutputFormat.table:
248-
_display_awaited_by_tasks_table(table)
249-
else:
250-
_display_awaited_by_tasks_csv(table, format=format)
251-
252-
253-
_row_header = ('tid', 'task id', 'task name', 'coroutine stack',
254-
'awaiter chain', 'awaiter name', 'awaiter id')
255-
256-
257-
def _display_awaited_by_tasks_table(table):
258-
"""Print the table in a simple tabular format."""
259-
print(_fmt_table_row(*_row_header))
260-
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)
261245
for row in table:
262-
print(_fmt_table_row(*row))
263-
264-
265-
def _fmt_table_row(tid, task_id, task_name, coro_stack,
266-
awaiter_chain, awaiter_name, awaiter_id):
267-
# Format a single row for the table format
268-
return (f'{tid:<10} {task_id:<20} {task_name:<20} {coro_stack:<50} '
269-
f'{awaiter_chain:<50} {awaiter_name:<15} {awaiter_id:<15}')
270-
271-
272-
def _display_awaited_by_tasks_csv(table, *, format):
273-
"""Print the table in CSV format"""
274-
if format == TaskTableOutputFormat.csv:
275-
delimiter = ','
276-
else:
277-
raise ValueError(f"Unknown output format: {format}")
278-
csv_writer = csv.writer(sys.stdout, delimiter=delimiter)
279-
csv_writer.writerow(_row_header)
280-
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}")
281247

282248

283249
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)