Skip to content
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

gh-121468: Show asyncio information in pdb #124367

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

gaogaotiantian
Copy link
Member

@gaogaotiantian gaogaotiantian commented Sep 23, 2024

This is a draft because we still need to decide on the format.

I'm aiming for something short, the original repr of asyncio task is just too long. For now it's like

gaotian@gaotian-mba cpython % ./python.exe example.py             
Task-1: <main pending>
> /Users/gaotian/programs/cpython/example.py(11)main()
-> breakpoint()

If pdb stops in an asyncio task, it will print an extra line showing the name of the task (Task-1), the name of the coroutine (main) and the status (pending).

As of now I think it will always be pending because we hit a breakpoint inside. However, we will add the feature to list all asyncio tasks in the future and allow switching between those, so we will have more status and it will be some important information.

I will work on the docs and the tests as long as the format is okay.

@@ -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 of asyncio.base_futures, so we could consider adding a lazy import of asyncio at line 606 to improve import time?

#109653
#118761

Copy link
Member Author

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 of pdb 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

@@ -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
Member Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants