mirror of
https://github.com/python/cpython.git
synced 2025-11-01 06:01:29 +00:00
gh-134861: revert "Add CSV and BSV output formats to asyncio ps" (#138187)
This reverts commitee72c95aa9and470cbe97a5
This commit is contained in:
parent
025a2135ef
commit
c779f2324d
3 changed files with 12 additions and 59 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
import argparse
|
import argparse
|
||||||
import ast
|
import ast
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import asyncio.tools
|
||||||
import concurrent.futures
|
import concurrent.futures
|
||||||
import contextvars
|
import contextvars
|
||||||
import inspect
|
import inspect
|
||||||
|
|
@ -10,9 +11,6 @@
|
||||||
import threading
|
import threading
|
||||||
import types
|
import types
|
||||||
import warnings
|
import warnings
|
||||||
from asyncio.tools import (TaskTableOutputFormat,
|
|
||||||
display_awaited_by_tasks_table,
|
|
||||||
display_awaited_by_tasks_tree)
|
|
||||||
|
|
||||||
from _colorize import get_theme
|
from _colorize import get_theme
|
||||||
from _pyrepl.console import InteractiveColoredConsole
|
from _pyrepl.console import InteractiveColoredConsole
|
||||||
|
|
@ -155,11 +153,6 @@ def interrupt(self) -> None:
|
||||||
"ps", help="Display a table of all pending tasks in a process"
|
"ps", help="Display a table of all pending tasks in a process"
|
||||||
)
|
)
|
||||||
ps.add_argument("pid", type=int, help="Process ID to inspect")
|
ps.add_argument("pid", type=int, help="Process ID to inspect")
|
||||||
formats = [fmt.value for fmt in TaskTableOutputFormat]
|
|
||||||
formats_to_show = [fmt for fmt in formats
|
|
||||||
if fmt != TaskTableOutputFormat.bsv.value]
|
|
||||||
ps.add_argument("--format", choices=formats, default="table",
|
|
||||||
metavar=f"{{{','.join(formats_to_show)}}}")
|
|
||||||
pstree = subparsers.add_parser(
|
pstree = subparsers.add_parser(
|
||||||
"pstree", help="Display a tree of all pending tasks in a process"
|
"pstree", help="Display a tree of all pending tasks in a process"
|
||||||
)
|
)
|
||||||
|
|
@ -167,10 +160,10 @@ def interrupt(self) -> None:
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
match args.command:
|
match args.command:
|
||||||
case "ps":
|
case "ps":
|
||||||
display_awaited_by_tasks_table(args.pid, format=args.format)
|
asyncio.tools.display_awaited_by_tasks_table(args.pid)
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
case "pstree":
|
case "pstree":
|
||||||
display_awaited_by_tasks_tree(args.pid)
|
asyncio.tools.display_awaited_by_tasks_tree(args.pid)
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
case None:
|
case None:
|
||||||
pass # continue to the interactive shell
|
pass # continue to the interactive shell
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,8 @@
|
||||||
"""Tools to analyze tasks running in asyncio programs."""
|
"""Tools to analyze tasks running in asyncio programs."""
|
||||||
|
|
||||||
from collections import defaultdict
|
from collections import defaultdict, namedtuple
|
||||||
import csv
|
|
||||||
from itertools import count
|
from itertools import count
|
||||||
from enum import Enum, StrEnum, auto
|
from enum import Enum
|
||||||
import sys
|
import sys
|
||||||
from _remote_debugging import RemoteUnwinder, FrameInfo
|
from _remote_debugging import RemoteUnwinder, FrameInfo
|
||||||
|
|
||||||
|
|
@ -233,56 +232,18 @@ def _get_awaited_by_tasks(pid: int) -> list:
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
class TaskTableOutputFormat(StrEnum):
|
def display_awaited_by_tasks_table(pid: int) -> None:
|
||||||
table = auto()
|
|
||||||
csv = auto()
|
|
||||||
bsv = auto()
|
|
||||||
# 🍌SV is not just a format. It's a lifestyle. A philosophy.
|
|
||||||
# https://www.youtube.com/watch?v=RrsVi1P6n0w
|
|
||||||
|
|
||||||
|
|
||||||
def display_awaited_by_tasks_table(pid, *, format=TaskTableOutputFormat.table):
|
|
||||||
"""Build and print a table of all pending tasks under `pid`."""
|
"""Build and print a table of all pending tasks under `pid`."""
|
||||||
|
|
||||||
tasks = _get_awaited_by_tasks(pid)
|
tasks = _get_awaited_by_tasks(pid)
|
||||||
table = build_task_table(tasks)
|
table = build_task_table(tasks)
|
||||||
format = TaskTableOutputFormat(format)
|
# Print the table in a simple tabular format
|
||||||
if format == TaskTableOutputFormat.table:
|
print(
|
||||||
_display_awaited_by_tasks_table(table)
|
f"{'tid':<10} {'task id':<20} {'task name':<20} {'coroutine stack':<50} {'awaiter chain':<50} {'awaiter name':<15} {'awaiter id':<15}"
|
||||||
else:
|
)
|
||||||
_display_awaited_by_tasks_csv(table, format=format)
|
print("-" * 180)
|
||||||
|
|
||||||
|
|
||||||
_row_header = ('tid', 'task id', 'task name', 'coroutine stack',
|
|
||||||
'awaiter chain', 'awaiter name', 'awaiter id')
|
|
||||||
|
|
||||||
|
|
||||||
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:
|
for row in table:
|
||||||
print(_fmt_table_row(*row))
|
print(f"{row[0]:<10} {row[1]:<20} {row[2]:<20} {row[3]:<50} {row[4]:<50} {row[5]:<15} {row[6]:<15}")
|
||||||
|
|
||||||
|
|
||||||
def _fmt_table_row(tid, task_id, task_name, coro_stack,
|
|
||||||
awaiter_chain, awaiter_name, awaiter_id):
|
|
||||||
# Format a single row for the table format
|
|
||||||
return (f'{tid:<10} {task_id:<20} {task_name:<20} {coro_stack:<50} '
|
|
||||||
f'{awaiter_chain:<50} {awaiter_name:<15} {awaiter_id:<15}')
|
|
||||||
|
|
||||||
|
|
||||||
def _display_awaited_by_tasks_csv(table, *, format):
|
|
||||||
"""Print the table in CSV format"""
|
|
||||||
if format == TaskTableOutputFormat.csv:
|
|
||||||
delimiter = ','
|
|
||||||
elif format == TaskTableOutputFormat.bsv:
|
|
||||||
delimiter = '\N{BANANA}'
|
|
||||||
else:
|
|
||||||
raise ValueError(f"Unknown output format: {format}")
|
|
||||||
csv_writer = csv.writer(sys.stdout, delimiter=delimiter)
|
|
||||||
csv_writer.writerow(_row_header)
|
|
||||||
csv_writer.writerows(table)
|
|
||||||
|
|
||||||
|
|
||||||
def display_awaited_by_tasks_tree(pid: int) -> None:
|
def display_awaited_by_tasks_tree(pid: int) -> None:
|
||||||
|
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
Add CSV as an output format for :program:`python -m asyncio ps`.
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue