gh-134861: Add 🍌SV output format to `python -m asyncio ps` (#137486)

Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
This commit is contained in:
Daniele Parmeggiani 2025-08-06 22:42:34 +02:00 committed by GitHub
parent 470cbe97a5
commit ee72c95aa9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 1 deletions

View file

@ -156,7 +156,10 @@ def interrupt(self) -> None:
) )
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 = [fmt.value for fmt in TaskTableOutputFormat]
ps.add_argument("--format", choices=formats, default="table") 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"
) )

View file

@ -236,6 +236,9 @@ def _get_awaited_by_tasks(pid: int) -> list:
class TaskTableOutputFormat(StrEnum): class TaskTableOutputFormat(StrEnum):
table = auto() table = auto()
csv = 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): def display_awaited_by_tasks_table(pid, *, format=TaskTableOutputFormat.table):
@ -273,6 +276,8 @@ def _display_awaited_by_tasks_csv(table, *, format):
"""Print the table in CSV format""" """Print the table in CSV format"""
if format == TaskTableOutputFormat.csv: if format == TaskTableOutputFormat.csv:
delimiter = ',' delimiter = ','
elif format == TaskTableOutputFormat.bsv:
delimiter = '\N{BANANA}'
else: else:
raise ValueError(f"Unknown output format: {format}") raise ValueError(f"Unknown output format: {format}")
csv_writer = csv.writer(sys.stdout, delimiter=delimiter) csv_writer = csv.writer(sys.stdout, delimiter=delimiter)