8000 gh-134861: Add CSV and 🍌SV output formats to `asyncio ps` by dpdani · Pull Request #134862 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-134861: Add CSV and 🍌SV output formats to asyncio ps #134862

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
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
make it a secret 🤫
  • Loading branch information
dpdani committed May 31, 2025
commit e44226d82a7c54811cad6ee4b7a7d770b6392f54
8 changes: 7 additions & 1 deletion Lib/asyncio/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,13 @@ def interrupt(self) -> None:
)
ps.add_argument("pid", type=int, help="Process ID to inspect")
formats = [fmt.value for fmt in asyncio.tools.TaskTableOutputFormat]
ps.add_argument("--format", choices=formats, default="table")
big_secret = asyncio.tools.TaskTableOutputFormat.bsv.value
formats_to_show = [
fmt for fmt in formats if fmt != big_secret
]
formats_to_show_str = f"{{{','.join(formats_to_show)}}}"
ps.add_argument("--format", choices=formats, default="table",
metavar=formats_to_show_str)
pstree = subparsers.add_parser(
"pstree", help="Display a tree of all pending tasks in a process"
)
Expand Down
6 changes: 5 additions & 1 deletion Lib/asyncio/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,15 @@ class TaskTableOutputFormat(Enum):
_header = ('tid', 'task id', 'task name', 'coroutine chain', 'awaiter name', 'awaiter id')


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

tasks = _get_awaited_by_tasks(pid)
table = build_task_table(tasks)
format_ = TaskTableOutputFormat(format_)
if format_ == TaskTableOutputFormat.table:
_display_awaited_by_tasks_table(table)
else:
Expand Down
Loading
0