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

Add option to prevent the debugger stealing the focus from the debug console. #193462

Closed
martinakos opened this issue Sep 19, 2023 · 10 comments
Closed
Assignees

Comments

@martinakos
Copy link

martinakos commented Sep 19, 2023

Based on my question in vscode-python:
microsoft/vscode-python#22017 (comment)

I want to be able to work with the debug console without the debugger stealing focus and repositioning the editor. Specially don't reposition the editor unless there is stepping through the code. The focus seems to get stolen when closing plot windows (matplotlib, open3d) launched from the debug console.

I've checked these similar issues:
vscodenpa/testissues#9533
#162873
microsoft/vscode-python-debugger#533
but none give me a solution.

Also I have tried disabling the Debug: Focus Editor On Break and Debug: Focus Window on Break options but don't stop this behaviour.

@roblourens
Copy link
Member

"debug.focusEditorOnBreak": false should do this for you, that doesn't work?

@roblourens roblourens added the info-needed Issue requires more information from poster label Sep 19, 2023
@martinakos
Copy link
Author

martinakos commented Sep 20, 2023

I've tried that option but doesn't solve my problem.

Notice in my case the debugger is stopped in a breakpoint already, then I move the editor somewhere else and I send to the debug console some code that opens a matplotlib plot. When I close the plot the editor jumps back to the breakpoint location where the program counter is and I lose the editor view I had. This is very annoying when I want to run my script with some data, stop it at a breakpoint and then experiment with/analyse the data and processing I do to it at a previous point in the function/stack. The editor keep jumping back to the PC location when closing plot windows and I have to again repeatedly find the piece of code I was analysing, which breaks my focus on the problem I'm trying to solve. Notice I'm not stepping through code, I'm just probing parts of the code in the debug console.

@roblourens
Copy link
Member

Oh, it's a slightly different scenario than I assumed, however I can't repro it. So you just click X to close the matplotlib window, then when the vscode is focused again, the editor moves back to where the debugger is paused?

I don't see this happening, could you share the code that you run in the debug console to make sure I am trying the same scenario? A screen recording might help too. https://gifcap.dev/

@martinakos
Copy link
Author

Yes, that's correct.
I'll try to put together some example code showing the effect. I can't show the code I'm working on, company rules.

@vscodenpa
Copy link

Hey @roblourens, this issue might need further attention.

@martinakos, you can help us out by closing this issue if the problem no longer exists, or adding more information.

@martinakos
Copy link
Author

Hi, sorry I had other work to do and I couldn't look at this. I found a test case.

I use one of matplotlib examples, tricontour_demo.py. . I have added a plt.ion() after importing matplotlib as I want to plot things interactively while I'm in a breakpoint.

The only thing special about this script is that it's long, so that I can illustrate the issue. I first put a breakpoint at the bottom, I scroll to the top, evaluate a few lines from the code in the debug console (as I would typically be doing when I'm debugging a script), for that I just select what I wan to evaluate and I have a shortcut to send it to the debug console. Then I create a new matplotlib figure in the debug console, and the editor position jumps to the breakpoint position! That's what I would like to avoid, as that forces me to have to move the editor again to wherever I was before I can continue with my debugging, breaking my concentration. Notice I launch the debugger with a launch configuration.

See attached video:

debugger_stealing_focus_example.mp4

@roblourens
Copy link
Member

Now I can repro. Seems to be caused by "PYDEVD_UNBLOCK_THREADS_TIMEOUT": "0". Do you know why you set that?

@roblourens
Copy link
Member

My interpretation of what that does is that you are paused in the debugger, and running a command in the debug console runs on a second thread. Since the timeout is 0, it is considered blocked, and debugpy does something to unblock it, which ends up "refreshing" the paused thread in the editor. You can see the callstack blink momentarily. So the editor ends up focused because from vscode's perspective, the debugger actually continued then paused again, so it will do the same thing it does when hitting a breakpoint. Does that make sense?

@martinakos
Copy link
Author

martinakos commented Dec 13, 2023

While I debug computer vision/geometric code I often visualise point clouds using the Open3D visualiser. This visualiser blocks while I'm inspecting the point cloud and until I close the window. While the Open3D visualiser is opened I keep getting repeated messages in the the debug console telling me that the evaluation is very slow and it may be deadlocked. I set these PYDEVD_xxx environment variables in my launch configurations to silence all these messages.
I demonstrated the issue using matplotlib as it's more known. But I often mix matplotlib and Open3D visualisation depending on the data I want to inspect, that's why I always have these environment variable set.

@roblourens
Copy link
Member

Ok. You might check whether using PYDEVD_UNBLOCK_THREADS_TIMEOUT but with a higher timeout fixes the original issue without causing the refocusing of the debug session that you see here? But I think that just given the way it's implemented, I can't do anything about this on vscode's side. You could open an issue on the debugpy repo to maybe get more detail too.

@github-actions github-actions bot locked and limited conversation to collaborators Jan 27, 2024
@aiday-mar aiday-mar added this to the December / January 2024 milestone Feb 6, 2024
@vs-code-engineering vs-code-engineering bot removed the info-needed Issue requires more information from poster label Dec 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants