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

KeyboardInterrupt When Running Selection/Line in Python Terminal with 'Shift+Enter' #24422

Closed
CardonaEA opened this issue Oct 4, 2024 · 30 comments · Fixed by #24418
Closed
Assignees
Labels
area-terminal bug Issue identified by VS Code Team member as probable bug triage-needed Needs assignment to the proper sub-team
Milestone

Comments

@CardonaEA
Copy link

CardonaEA commented Oct 4, 2024

Environment:
Operating System: Windows 11
VS Code Version: 1.94.0
Python Extension Version: v2024.16.0

Steps to reproduce:

Default setting: the 'shift+enter' keyboard shortcut Runs Selection/Line in Python REPL.

  1. Ensure that the setting "python.REPL.sendToNativeREPL" is set to false. (This setting leads to the 'Shift+Enter' keyboard shortcut running the Selection/Line in the Python Terminal.)
  2. Open a Python script file (.py) in VS Code.
  3. Highlight a line or selection of code in the editor.
  4. Press Shift+Enter to run the selection or line in the Python Terminal.

Expected Behavior:
The selected line or code executes in the Python Terminal without any interruptions or errors.

Actual Behavior:
A KeyboardInterrupt is outputted before the selection or line continues executing in the Python Terminal.

Additional Information:

  • The issue occurs consistently when running a selection or line with Shift+Enter with the specified configuration.
  • The KeyboardInterrupt appears even when the execution continues after the interrupt message.
  • If the execution starts from a Python terminal, an error message is displayed, but the KeyboardInterrupt does not appear anymore.
  • The issue can be also triggered by setting a different keyboard shortcut.
Screen.Recording.2024-10-04.211253.mp4
Screen.Recording.2024-10-04.211730.mp4
@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label Oct 4, 2024
@CardonaEA CardonaEA changed the title Bug: KeyboardInterrupt When Running Selection/Line in Python Terminal with 'Shift+Enter Bug: KeyboardInterrupt When Running Selection/Line in Python Terminal with 'Shift+Enter' Oct 4, 2024
@CardonaEA CardonaEA changed the title Bug: KeyboardInterrupt When Running Selection/Line in Python Terminal with 'Shift+Enter' KeyboardInterrupt When Running Selection/Line in Python Terminal with 'Shift+Enter' Oct 4, 2024
@levibaguley
Copy link

levibaguley commented Oct 5, 2024

I'm seeing the same thing. I rolled back to 14.1 and it doesn't do that anymore. Click dropdown on "uninstall" to roll back and uncheck "Auto update". I'm planning on coming back here at some point to check if it's been fixed.

@CardonaEA
Copy link
Author

Yes, no issue with v2024.14.1. Thanks.

@lenarddome
Copy link

I was experiencing the same issue and can confirm that rolling back to previous versions gets rid of it.

@nbwosm
Copy link

nbwosm commented Oct 7, 2024

Thanks @levibaguley! I had the same issue and this fixed.

@breininger88
Copy link

Phew. Same issue and this worked. Thanks!

@AdrianNewbiePython
Copy link

Hi. Thank you all for your contributions.
Just as it is shown in the video of @CardonaEA , the error started me after I disabled the REPL to be executed after the keyboard shortcut SHIFT + ENTER.

However, even specifying in "Preferences: Open Workplace Settings (JSON)" the setting "python.REPL.sendToNativeREPL" to false, the KeyboardInterrupt still shows up. I don't know if it is related to the issue, but even if I still turn it to false in "Preferences: Open Workplace Settings (JSON)", in the page "Preferences: Open Default Settings (JSON)" (which I cannot edit), the setting "python.REPL.sendToNativeREPL" is still set true.

@kcerniauskas3
Copy link

Issue remains in v2024.18.0.

@jafar-the-amazing
Copy link

Rolling Back did fix the issue and as @kcerniauskas3 said ; it still remains in v2024.18.0.

@dharmatech
Copy link

dharmatech commented Nov 5, 2024

I'm seeing the same thing. I rolled back to 14.1 and it doesn't do that anymore. Click dropdown on "uninstall" to roll back and uncheck "Auto update". I'm planning on coming back here at some point to check if it's been fixed.

I see folks have rolled back to 14.1 to workaround the issue.

But is it really required? Yes, the KeyboardInterrupt appears in the console, but is it actually causing a functional issue besides that?

I'm using version v2024.18.0 and yes the KeyboardInterrupt is happening, but other than that the extension appears to work OK.

@rodo-nunez
Copy link

I'm seeing the same thing. I rolled back to 14.1 and it doesn't do that anymore. Click dropdown on "uninstall" to roll back and uncheck "Auto update". I'm planning on coming back here at some point to check if it's been fixed.

I see folks have rolled back to 14.1 to workaround the issue.

But is it really required? Yes, the KeyboardInterrupt appears in the console, but is it actually causing a functional issue besides that?

I'm using version v2024.18.0 and yes the KeyboardInterrupt is happening, but other than that the extension appears to work OK.

Yes, it is. At least for me.

That KeyboardInterrupt error was stopping my session after a real error or warning. So I was not able to debug my code without losing a lot of time and rerunning everything again and again. So I stopped using the extension and went back to another IDE not based on VSCode.

@anthonykim1
Copy link

Thanks everyone for the input here.
Is everyone on Windows? I can't seem to repro on my MacOS ARM machine.
I DO see the keyboard interrupt on my Windows machine though.

@github-actions github-actions bot added the info-needed Issue requires more information from poster label Nov 6, 2024
@anthonykim1 anthonykim1 added bug Issue identified by VS Code Team member as probable bug and removed triage-needed Needs assignment to the proper sub-team labels Nov 6, 2024
@levibaguley
Copy link

Yes, Windows 10 for me

@anthonykim1
Copy link

anthonykim1 commented Nov 6, 2024

I see, can folks also give 2024.16.1 a try and see whether it also adds the keyboard interrupt or not?
I personally don't see the keyboard interrupt on 16.1 but just wanted to make sure. Make sure to restart extension and run command

Edit: After restarting extension, and reloading with Python clear cache, I can repro this on 16.1 too

'Python: Clear Cache and Reload' via command palette (cmd/ctrl + shift + p)
Trying to narrow down the cause here :) Thanks in advance.

@rodo-nunez
Copy link

rodo-nunez commented Nov 6, 2024

it does fail for me

Image

@rodo-nunez
Copy link

v2024.15.2024092702 fails for me

Image

v2024.15.2024090406 works fine for me

Image

Probably the bug was introduced somewhere in-between

Image

@anthonykim1
Copy link

Thanks for this @rodo-nunez This is incredibly helpful!
I will go further investigate this and try to come up with the fix. Will let you all know if I have any updates/fix :)

@rodo-nunez
Copy link

rodo-nunez commented Nov 6, 2024

Using binary search:

v2024.15.2024091801 failed
v2024.15.2024091202 worked fine
v2024.15.2024091601 failed
v2024.15.2024091301 failed

So my guess is that the bug was introduced on v2024.15.2024091301.

@rodo-nunez
Copy link

@anthonykim1 also, I was reproducing that using the "Python: Run Selection/Line in Python Terminal" command. I always change it to Ctrl+Enter, to be able to freely choose between "Python: Run Selection/Line in Python Terminal" and "Python: Run Selection/Line in Python REPL" whenever I want.

Image

On v2024.15.2024091301, I don't see problems with the REPL, only with the Terminal. But I don't use the REPL that much.

Image

@anthonykim1
Copy link

Ok, thanks to @rodo-nunez I was able to figure out where this is coming from quickly.

Its from this PR: https://github.com/microsoft/vscode-python/pull/24078/files
where we switched over to use executeCommand instead of sendText internally to send over Python code for Terminal REPL.
Now will try to come up with a fix without breaking people.

For now, the workaround to not get this keyboard interrupt would be going to setting and then disabling shell integration:
Image

And Yes! the REPL you mentioned in the editor is our new native REPL. It has intellisense and syntax highlighting, autocomplete so feel free to give it a try :)

@nbwosm
Copy link

nbwosm commented Nov 6, 2024

@anthonykim1 I upgraded to v2024.18.0 and disabled shell integration and can confirm that I am not getting the KeyboardInterupt error. Thanks.

Follow-up: After having made these changes, I noticed a modest amount of latency in sending the code to the Python terminal via Shift + Enter and getting executed. I have reverted to v2024.14.1 and undone the shell disable. This was most noticeable executing matplotlib plots.

@stats9
Copy link

stats9 commented Nov 6, 2024

Image

I'm using version 2024.18.0 and I used the prerelease version, but unfortunately for every line of code I run through the script, I have this issue keyboardInterrupt.
the shortcut I defined is CTRL + Enter, but the shortcut I changed is the same.
I really don't know what idea I can implement to solve this problem.

update:

i add this line to my jason settings (workspace jason settings):
"terminal.integrated.shellIntegration.enabled": false,
and fix my problem!
i disable it shell integration actually.

@anthonykim1 anthonykim1 removed bug Issue identified by VS Code Team member as probable bug info-needed Issue requires more information from poster labels Nov 11, 2024
@anthonykim1 anthonykim1 transferred this issue from microsoft/vscode-python Nov 11, 2024
@microsoft microsoft deleted a comment from vs-code-engineering bot Nov 11, 2024
@anthonykim1
Copy link

Hi folks, I'm actively working on to resolve this with the PR here: #24418
Will post again once I have changes merged and you all can test the latest pre-release to give it a try.
Thanks again for patience :)

@anthonykim1 anthonykim1 added bug Issue identified by VS Code Team member as probable bug area-terminal labels Nov 12, 2024
@anthonykim1 anthonykim1 transferred this issue from microsoft/vscode Nov 12, 2024
@anthonykim1 anthonykim1 added this to the November 2024 milestone Nov 12, 2024
@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label Nov 12, 2024
@Jintram
Copy link

Jintram commented Nov 12, 2024

Just to add, I also experienced this issue on a Mac. In addition to the issue with "KeyboardInterrupt" described above, trying to run some of my code through SHIFT+ENTER also made the terminal become unresponsive. Rolling back to Python v2024.14.1 as suggested above solved both issues.

My system that showed the issue:
Macbook Pro 15-inch, 2018
macos sequoia 15.1 (24B83)

VS code version: 1.95.2
Python extension version: v2024.18.1

@anthonykim1
Copy link

Just merged #24418 so please give the pre-release of Python version a try starting tomorrow (Beginning November 13th). Let me know if people suffer from problem after trying out tomorrow's pre-release of Python extension. Make sure you reload extension and run Python Clear Cache and reload after you update!

SHIFT+ENTER also made the terminal become unresponsive.

This sounds like a different issue. @Jintram
But how are you getting the keyboard interrupt when shift+enter made your terminal unresponsive?
Are you sending code to the native repl isntead? Feel free to file this as a separate issue.

@github-actions github-actions bot added the info-needed Issue requires more information from poster label Nov 12, 2024
@jafar-the-amazing
Copy link

Hi @anthonykim1 just tried it and everything seems normal and fine , thanks for that.
Same settings just switched to pre-release.

@Jintram
Copy link

Jintram commented Nov 13, 2024

@anthonykim1 : I tried v2024.21.2024111202 (pre-release), there, everything works normal, also my function that caused the terminal unresponsiveness now executes normally.
So thanks for that!!

Attached a movie of what happens with Python v2024.20.0.
As you can see there are additional issues with the terminal aside from the keyboard thing, I don't know how to best describe it.

Perhaps the origin is somehow in my code, which is rather untested.
But in my Mac's terminal or with the pre-release Python version, these issues disappear entirely and all my functions execute normally.

As this issue disappeared with the pre-release, I guess I don't open a new issue.

Again, thanks for your work fixing this issue in any case!

Screen.Recording.2024-11-13.at.10.35.44.mov

@github-actions github-actions bot removed the info-needed Issue requires more information from poster label Nov 13, 2024
@anthonykim1
Copy link

Thanks everyone for testing this.

Attached a movie of what happens with Python v2024.20.0.
As you can see there are additional issues with the terminal aside from the keyboard thing, I don't know how to best describe it.

Interesting, I wonder if same thing happens if you don't highlight anything and use the "smart send" setting (you would just shift+enter on your expression and expect that entire expression or more to get sent over to terminal).

I'm glad this went away with the pre-release but please let me know via filing new issue when you start experiencing this with later pre-release or upcoming release towards late november/early december.
You can directly cc me :)

Thanks

@github-actions github-actions bot added the info-needed Issue requires more information from poster label Nov 13, 2024
@stats9
Copy link

stats9 commented Nov 13, 2024 via email

@anthonykim1
Copy link

Make sure you test on the latest pre-release for Python extension. @stats9
Image
Also make sure to reload extensions, and exit out of any residual terminal REPL, run Python Clear Cache and Reload.

@stats9
Copy link

stats9 commented Nov 13, 2024

i editted my words, keyboardInterrupt is fixed with pre-release version of python when using python 3.13.0 or older versions, but
i have indentation error with python 3.13.0!
I am attaching two images. I run exactly the same file with two versions of Python. First with version 3.13.0 and then with version 3.12.7
You can see that in version 3.13.0,
indentation error can also be seen during execution by using SHIFT + ENTER.
Of course, an issue has been opened for indentation error in Python 3.13.0, but I wanted to share the simultaneous execution of a file by two version of Python, and to point out that the problem is specific to Python 3.13.0.

image1 for python 3.13.0:

Image

image2 for python 3.12.7:

Image

@github-actions github-actions bot removed the info-needed Issue requires more information from poster label Nov 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-terminal bug Issue identified by VS Code Team member as probable bug triage-needed Needs assignment to the proper sub-team
Projects
None yet