Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-121468: Show asyncio information in pdb#124367

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
gaogaotiantian merged 7 commits intopython:mainfromgaogaotiantian:pdb-asyncio-basic
Mar 14, 2025
Merged
Changes from1 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
42 changes: 42 additions & 0 deletionsLib/pdb.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -79,6 +79,7 @@
import codeop
import pprint
import signal
import asyncio
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Line 614 has deferred import ofasyncio.base_futures, so we could consider adding a lazy import ofasyncio at line 606 to improve import time?

#109653
#118761

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

asyncio will be used as long as pdb is used.pdb is not an module that is often imported explicitly or implicitly, I don't think import time ofpdb is specifically critical.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

You're right. I didn't realize that at the time

import inspect
import textwrap
import tokenize
Expand DownExpand Up@@ -361,6 +362,9 @@ def __init__(self, completekey='tab', stdin=None, stdout=None, skip=None,
self._chained_exceptions = tuple()
self._chained_exception_index = 0

self._running_loop = None
self._current_task = None

def set_trace(self, frame=None):
Pdb._last_pdb_instance = self
if frame is None:
Expand DownExpand Up@@ -407,6 +411,8 @@ def setup(self, f, tb):
self.curframe_locals = self.curframe.f_locals
self.set_convenience_variable(self.curframe, '_frame', self.curframe)

self.set_convenience_variable(self.curframe, '_asynctask', self._current_task)

if self._chained_exceptions:
self.set_convenience_variable(
self.curframe,
Expand DownExpand Up@@ -596,6 +602,38 @@ def _hold_exceptions(self, exceptions):
self._chained_exceptions = tuple()
self._chained_exception_index = 0

def _get_asyncio_loop_and_task(self):
try:
loop = asyncio.get_event_loop()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

You can replace this with direct call to current_task and if it exists get loop from it, using get_event_loop can have unwanted consequences

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Yeah I will change this.

task = asyncio.current_task(loop)
except RuntimeError:
loop = task = None
return loop, task

def _asyncio_task_repr(self, task):
import asyncio.base_futures

if task.cancelling() and not task.done():
status = 'cancelling'
else:
info = asyncio.base_futures._future_repr_info(task)
status = info[0]

coro = task._coro

if coro is not None:
if hasattr(coro, '__qualname__') and coro.__qualname__:
coro_name = coro.__qualname__
elif hasattr(coro, '__name__') and coro.__name__:
coro_name = coro.__name__
else:
# Stop masking Cython bugs, expose them in a friendly way.
coro_name = f'<{type(coro).__name__} without __name__>'
else:
coro_name = 'unknown'

return f"{task.get_name()}: <{coro_name} {status}>"

def interaction(self, frame, tb_or_exc):
# Restore the previous signal handler at the Pdb prompt.
if Pdb._previous_sigint_handler:
Expand All@@ -606,6 +644,8 @@ def interaction(self, frame, tb_or_exc):
else:
Pdb._previous_sigint_handler = None

self._running_loop, self._current_task = self._get_asyncio_loop_and_task()

_chained_exceptions, tb = self._get_tb_and_exceptions(tb_or_exc)
if isinstance(tb_or_exc, BaseException):
assert tb is not None, "main exception must have a traceback"
Expand DownExpand Up@@ -995,6 +1035,8 @@ def completedefault(self, text, line, begidx, endidx):
# Pdb meta commands, only intended to be used internally by pdb

def _pdbcmd_print_frame_status(self, arg):
if self._current_task:
self.message(self._asyncio_task_repr(self._current_task))
self.print_stack_trace(0)
self._show_display()

Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp