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

Code finishes fully executing after 'Disconnect' / Shift-F5 / terminate debugging #1686

Closed
karthiknadig opened this issue Sep 30, 2024 · 14 comments
Assignees
Labels
needs repro Issue has not been reproduced yet

Comments

@karthiknadig
Copy link
Member

Discussed in microsoft/vscode-python#24205

Originally posted by PeterMuhlberger September 28, 2024
I recently ran into this: While doing a little step-through debugging with the vscode Python Debugger (extension), I tried to terminate the debugger by pressing the icon to disconnect the debugger. Instead of ending with a KeyBoardInterrupt as usual, the code after the breakpoint ran completely, creating quite a mess. The same problem occurs if I use Shift-F5, but not when I use the small square that terminates cell execution. I've tried a wide range of possible fixes to the problem, but it persists.

Before going any further, I should ask if this is the right place to report this problem and whether I should report it directly to Issues here? Beyond this: has anyone else run into this? Any suggested solutions?

(I've tried, among other things: Reinstalling my Python and Jupyter extensions; installing 2 month old versions of these extensions (before this problem started happening); disabling other extensions; inserting the default launch.json file in my workspace; trying to see if the problem occurs in a new notebook file outside the workspace I encountered the problem initially (it does); checking if setting the breakpoint above the initial line still causes continued code execution (it does); looking for potentially problematic lines in settings.json (saw none)).

@karthiknadig karthiknadig transferred this issue from microsoft/vscode-python Sep 30, 2024
@github-actions github-actions bot added the needs repro Issue has not been reproduced yet label Sep 30, 2024
@PeterMuhlberger
Copy link

Thanks Karthik and Kacie! Need anything else from me? It may help to know that I'm using MX Linux, current stable. I could provide more details about hardware / software. In terms of reproduction, it reproduces perfectly on my computer--the problem always occurs. Of course, you're probably thinking of reproduction by someone else.

@rchiodo
Copy link
Contributor

rchiodo commented Sep 30, 2024

Are you doing this in a notebook? Stop debugging does something different depending upon how you're debugging something.

In a jupyter notebook, it sends a keyboard interrupt (or interrupt kernel). But based on where you are in the cell, it might not handle the interrupt and just keep going.

In a regular python file if you launched the program with the debugger, stop debugging will just kill the process. If you attached to the program, it will detach, but the process will continue to run.

@PeterMuhlberger
Copy link

Thanks rchiodo: Yes, I'm doing this in a jupyter notebook. I never had this problem before: terminating the debugger always stopped subsequent code from being executed. I think the problem started after a recent vscode update. It doesn't seem to matter where I am in a cell--it always continues execution. I tried creating a new notebook with a very simple print function in one cell and a 2nd cell with one line that called that function. I put the breakpoint on that line. When I terminated the debug, the print executed--indicating that lines continued to run after termination. I've also replicated this bug in multiple places in more complex code. The one thing I've thought of that I haven't tried yet is to reinstall vscode--in part because I had reinstalled it recently.

@rchiodo
Copy link
Contributor

rchiodo commented Sep 30, 2024

That has entirely to do with the kernel itself though. You can verify this by just running a cell that calls say some C++ code that sits there forever. You can't interrupt it. Sometimes a keyboard interrupt doesn't work.

We should double check with the jupyter team though, maybe they recently removed the keyboard interrupt. I could be wrong but the jupyter extension used to interrrupt the kernel on the detach.

@rchiodo
Copy link
Contributor

rchiodo commented Sep 30, 2024

@DonJayamanne @amunger is that your recollection as well? Debug detach should interrupt the kernel? Maybe I'm remembering wrong.

@amunger
Copy link

amunger commented Sep 30, 2024

I'm pretty confident that nothing changed there on the Jupyter extension side recently.
I'm still able to stop a debugging cell with interrupt while at a breakpoint:

image

@PeterMuhlberger
Copy link

By way of comparison, here is what I see. A break at the breakpoint, ask to terminate, and it executes the function
break_from_debugger_continues_execution

@rchiodo
Copy link
Contributor

rchiodo commented Sep 30, 2024

@amunger do you know where the kernel.interrupt is fired from? Or are you saying you hit the 'interrupt' button?

@amunger
Copy link

amunger commented Sep 30, 2024

I'm using the interrupt button, yes, which causes core to call the interrupt handler on the controller and jupyter sends an interrupt to the kernel https:/microsoft/vscode-jupyter/blob/4151b43c83be7e4f2ebca5e0958d06100d490cac/src/notebooks/notebookCommandListener.ts#L139

@rchiodo
Copy link
Contributor

rchiodo commented Sep 30, 2024

Okay so maybe I'm wrong, maybe we never had debug automatically do an interrupt. The user has to pick that option explicitly. Make sense now that I think about it.

You might have started debugging in order to debug the first part of the cell, but you want it to continue and you don't care about debugging anymore.

If you want it to stop debugging, you hit the interrupt button.

@rchiodo rchiodo closed this as completed Sep 30, 2024
@rchiodo
Copy link
Contributor

rchiodo commented Sep 30, 2024

@PeterMuhlberger if you want it to interrupt execution, you have to explicitly click the 'interrupt' button.

@PeterMuhlberger
Copy link

Hi rchiodo: For my 2 bits: I am talking about the Disconnect button (or, alternatively, Shift-F5) on the debugging tools palette that appears. These in the past ended code execution from what I can recall (I remember seeing keyboard interrupt messages after using that button). If I wanted the code to continue executing, there is the Continue or F5 button. What you're saying is that now I need to go back to the cell at which I started debugging, which can be quite far from the break point, and use the Stop Cell Execution square to the left. That's do-able, but seems awkward.

@rchiodo
Copy link
Contributor

rchiodo commented Oct 1, 2024

There should also be an 'interrupt' button at the top of the notebook too.

Image

You can also suggest a feature request on the jupyter extension to have debug detach automatically do an interrupt.

@PeterMuhlberger
Copy link

Thanks rchiodo! I've avoided that interrupt button in the past because I imagined it might restart the kernel, but it doesn't.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs repro Issue has not been reproduced yet
Projects
None yet
Development

No branches or pull requests

5 participants