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
Show file tree
Hide file tree
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
PrevPrevious commit
NextNext commit
Remove the print
  • Loading branch information
@gaogaotiantian
gaogaotiantian committedMar 11, 2025
commitae16c8bdc6fbe507c3d54c442fea2c047bbea0b5
6 changes: 5 additions & 1 deletionDoc/library/pdb.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -304,16 +304,20 @@ sets a global variable ``$foo`` which you can use in the debugger session. The
less likely to interfere with your program compared to using normal variables
like ``foo = 1``.

There arethree preset *convenience variables*:
There arefour preset *convenience variables*:

* ``$_frame``: the current frame you are debugging
* ``$_retval``: the return value if the frame is returning
* ``$_exception``: the exception if the frame is raising an exception
* ``$_asynctask``: the asyncio task if pdb stops in an async function

.. versionadded:: 3.12

Added the *convenience variable* feature.

.. versionadded:: 3.14
Added the ``$_asynctask`` convenience variable.

.. index::
pair: .pdbrc; file
triple: debugger; configuration; file
Expand Down
3 changes: 3 additions & 0 deletionsDoc/whatsnew/3.14.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -811,6 +811,9 @@ pdb
fill in a 4-space indentation now, instead of inserting a ``\t`` character.
(Contributed by Tian Gao in :gh:`130471`.)

* ``$_asynctask`` is added to access the current asyncio task if applicable.
(Contributed by Tian Gao in :gh:`124367`.)


pickle
------
Expand Down
41 changes: 7 additions & 34 deletionsLib/pdb.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -364,7 +364,6 @@ 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, *, commands=None):
Expand DownExpand Up@@ -409,7 +408,8 @@ def setup(self, f, tb):
tb = tb.tb_next
self.curframe = self.stack[self.curindex][0]
self.set_convenience_variable(self.curframe, '_frame', self.curframe)
self.set_convenience_variable(self.curframe, '_asynctask', self._current_task)
if self._current_task:
self.set_convenience_variable(self.curframe, '_asynctask', self._current_task)
self._save_initial_file_mtime(self.curframe)

if self._chained_exceptions:
Expand DownExpand Up@@ -620,37 +620,12 @@ def _hold_exceptions(self, exceptions):
self._chained_exceptions = tuple()
self._chained_exception_index = 0

def_get_asyncio_loop_and_task(self):
def_get_asyncio_task(self):
try:
loop = asyncio.get_event_loop()
task = asyncio.current_task(loop)
task = asyncio.current_task()
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}>"
task = None
return task

def interaction(self, frame, tb_or_exc):
# Restore the previous signal handler at the Pdb prompt.
Expand All@@ -662,7 +637,7 @@ 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()
self._current_task = self._get_asyncio_task()

_chained_exceptions, tb = self._get_tb_and_exceptions(tb_or_exc)
if isinstance(tb_or_exc, BaseException):
Expand DownExpand Up@@ -1067,8 +1042,6 @@ 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._validate_file_mtime()
self._show_display()
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp