-
Notifications
You must be signed in to change notification settings - Fork 142
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
await
keyword support in Debug Console
#951
Comments
Thanks for the feature request! We are going to give the community 60 days from when this issue was created to provide 5 👍 upvotes on the opening comment to gauge general interest in this idea. If there's enough upvotes then we will consider this feature request in our future planning. If there's unfortunately not enough upvotes then we will close this issue. |
Thank you to everyone who upvoted this issue! Since the community showed interest in this feature request we will leave this issue open as something to consider implementing at some point in the future. We do encourage people to continue 👍 this issue as it helps us prioritize our work based on what the community seems to want the most. |
Regarding the implementation it might be worth checking out what IPython did to archive top-level awaits in the REPL: https://ipython.readthedocs.io/en/stable/interactive/autoawait.html#internals |
@int19h should we transfer this to debugpy? |
I see that this enhancement is being worked on. But I was wondering what other people do to help debug their code. I have a lot of variables who's values that I can only see if I await them inside a function and that's extremely inconvenient for me as I'll have to re-run my current .py file. Is there a better way to debug variables that need to be retrieved from awaiting coroutines? |
I was thinking how to implement this. The major issue is that the tracing mode in which the debugger pauses is a sync function and thus we need a way to call async code from sync code (which in general is a no-no but is a requisite for this to work at all because we'll be paused at a breakpoint inside of the tracing from a call which went async -> sync). There are 2 possible approaches I thought of here:
I'll try a bit with approach 2 to see how far I get there. |
I've tried approach 2 and the basics work (i.e.: for a simple coroutine with a sleep) , but after checking the code I'm not sure this is reasonable. The basics of the Also, in the end there can be only 1 loop active, so, the only way I got it to work was calling Trying to create a new native loop on top of the same thread and set it with set_event_loop/_set_running_loop also didn't yield good results. Given that, I think going with option 1 (evaluating each new async call in a new thread) will be less brittle (even with the known cons) -- only for |
Might also be interesting to take a look at this PyCharm plugin: https://github.com/uriyyo/pycharm-evaluate-async-code |
@septatrix thank you for the reference... It seems it uses the same loop and monkey-patches many things to make it reentrant (https://github.com/uriyyo/pycharm-evaluate-async-code/blob/master/src/main/java/com/uriyyo/evaluate_async_code/AsyncPyDebugUtils.kt#L80) -- i.e.: with those patches I'm a bit wary of all the monkey-patching done to make that possible. Also, from the implementation I get the impression that if you have other things scheduled to run in the original loop it could run those things, which is not something we want (so, I get the impression that this approach would be a no-go due to that as we don't want to run unrelated scheduled tasks while we wait for the task we're evaluating -- note that I haven't really tested it, but from code-reviewing that code I'd say this isn't an ideal approach). So, I guess for now I'm still going with option 1. p.s.: @septatrix really thanks for the link, it's always nice to know how other implementations work ;) |
Discussed in microsoft/vscode-python#15842
Originally posted by jamesstidard April 2, 2021
It would be nice to be able to use the
await
keyword in the Debug Console when sitting on a breakpoint.The
asyncio
module actually has a REPL that supports this in the latest versions of Python:If it's possible to replicate this in the Debug Console, I think this would be a very welcome feature for the python heads that live in
asyncio
.If it's all part of the same system, it would also be nice to await watched variables in the Run & Debug Panel. This area:
The text was updated successfully, but these errors were encountered: