-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -79,6 +79,7 @@ | |||
import codeop | |||
import pprint | |||
import signal | |||
import asyncio |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
Lib/pdb.py
Outdated
@@ -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() |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
Okay I want to move this forward so I decided to do baby step. For this PR, I only added the |
Misc/NEWS.d/next/Library/2025-03-11-21-52-33.gh-issue-121468.WsEP02.rst
Outdated
Show resolved
Hide resolved
|
|
|
|
|
|
|
|
|
|
The iOS and Android test appear to be passing on a re-run; trying to see if I can identify the cause. |
@gaogaotiantian I can confirm this isn't an iOS/Android issue - it's an issue with test ordering. I can reproduce the test failure on macOS by running The failure isn't a failure of the test itself - it's a failure caused by the test modifying the test environment:
On a re-run, the test passes, because on entry, the test already has an event loop policy. What isn't clear to me is why this isn't a failure when you run the test by itself. I'm not completely sure what the right fix is here. Calling |
@freakboy3742 Thank you for finding this. I checked the other code using |
g> @freakboy3742 Thank you for finding this. I checked the other code using I won't profess to being an asyncio expert - but my understanding is that the method is being deprecated because the underlying feature is no longer required, so there's no replacement API. My guess is that when the deprecation process is finalised, this "policy cleanup" bug will also disappear - because there's no state that will be inconsistent between the start and end of the test. I'll push up a PR that implements this fix, and tag someone with more async experience to make sure I'm not missing anything.
FWIW - that approach won't work (or, at least, if you use that approach, the test won't run be able to run at all on iOS, Android or Emscripten) - mobile and web platforms don't support subprocesses. |
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 likeIf 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.