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

Terminal Keyboard Inputs not being accepted #370

Closed
yousefabuz17 opened this issue Aug 15, 2020 · 25 comments
Closed

Terminal Keyboard Inputs not being accepted #370

yousefabuz17 opened this issue Aug 15, 2020 · 25 comments
Assignees
Labels
bug Something isn't working P0 The issue is important, and should be prioritized for new work.

Comments

@yousefabuz17
Copy link

Bug: Python Interpreter Extension

------------------------------------------------------------------------------------------------->

Steps to cause the bug to occur

  1. Latest version of python contains this bug where if you type a code simple like:
    age = input("Enter age: )
    print(age)

In the terminal when you type in a number or anything and then click enter, it would not accept the user input and took me awhile to realize its because of the new update.

Actual behavior

Terminal not accepting user inputs

Expected behavior

Terminal needs to accept user inputs in order to run the full code if necessary.

Solution:
Downgrade the python interpreter from 2020.8.101144 to one below it.

@dongchenyu163
Copy link

The same issue at the Ubuntu 18.04.3. But windows10 not.
The python debugger will stucked because it can not receive any input while input() function is executing.
Moreover, the input characters will not send to the python debugger but sending to the terminal after the python debugger is stopped.

Test program is below:

res = input("Enter something:")  # Program stuck here. Stop the debugger.
print(res)

issue

@yousefabuz17
Copy link
Author

Yes luckily downgrading the python interpreter solved this annoying issue. I had to uninstall VSCode, remove all extensions just to find out all I had to do was downgrade the latest python extension lol.

@karthiknadig karthiknadig transferred this issue from microsoft/vscode-python Aug 17, 2020
@karthiknadig
Copy link
Member

karthiknadig commented Aug 17, 2020

@yousefabuz17 @dongchenyu163 Try adding "redirectOutput": true to your launch.json debug configuration, see #296 (comment). This was changed recently to allow better control of IO redirection.

@int19h we may need to handle this based on console setting. We should also change the name of the setting to better reflect that it redirects input and output streams.

@yousefabuz17
Copy link
Author

@karthiknadig ok I will definitely try that. Thanks for the feedback. I'm hoping a new update will be released soon so no one else will have this issue.

@fabioz
Copy link
Collaborator

fabioz commented Aug 17, 2020

I still haven't investigated why that happens, but I can confirm that I can reproduce it on Ubuntu while it still works on Windows.

I tried just putting the stdin patching in place again, but it didn't seem to make any difference (so, it's probably related to something else).

@McCarthyCode
Copy link

McCarthyCode commented Aug 17, 2020

This appears to be a Linux issue. I'm running Arch 5.7.8 and am experiencing this problem.

@yousefabuz17
Copy link
Author

@mattmc318 you think so? I believe it's the Python Extension it's self that's the issue ever since the new update a couple days ago. Downgrading it obviously fixed the issue but it has to do with whatever they changed in the new update. @karthiknadig mentioned to add redirectOutput in launch.json while debugging but didn't work for me so.

I'm also running this with Visual Studio Code on a Mac latest version.

@McCarthyCode
Copy link

McCarthyCode commented Aug 17, 2020

@yousefabuz17 Maybe not, then. I was just basing that assessment off of other comments. I'm new here, lol. It seems to work on Windows, but that could be just because it wasn't updated, or for any other reason besides it being platform-specific.

@karthiknadig
Copy link
Member

One of the things that changed with the new version of the extension was the debugger version. We updated the extension to the latest debugger version. So when you downgrade the extension, you are automatically downgrading the debugger.

@zlcnup
Copy link

zlcnup commented Aug 18, 2020

@karthiknadig "redirectOutput": true in launch.json didn't work for me. I encountered this issue after updating VSCODE(1.48.0) and Python extension(2020.8.101144) on Win10.

@yousefabuz17
Copy link
Author

@zlcnup yea that didn't work for me either. I'm just waiting till a solution gets released or they simply update the python extension again

@int19h
Copy link
Contributor

int19h commented Aug 18, 2020

It's the reverse - "redirectOutput": true also redirects stdin, so it might break some libraries that rely on sys.stdin being exactly the type that Python normally makes it be. Conversely, "redirectOutput": false is what you want for minimum interference.

Also, the default for that setting already depends on "console" - it's only true by default if that's set to "internalConsole", and false otherwise.

@int19h
Copy link
Contributor

int19h commented Aug 18, 2020

This is a regression caused by 57ec4c4 - using a separate process group breaks terminal I/O, even though stdin is still propagated correctly. Need to revert that part of the change, and come up with a different way to manage the process tree.

@int19h int19h self-assigned this Aug 18, 2020
@int19h int19h added bug Something isn't working P0 The issue is important, and should be prioritized for new work. labels Aug 18, 2020
@zlcnup
Copy link

zlcnup commented Aug 18, 2020

I re-test on pure local Win10 using "redirectOutput": both true and false, and debug input() working normally. But it doesn't work on vscode-server by Remote-SSH DEBUG manner (remote machine: Ubuntu16.04, local machine: Win10). Both machines have the same Python Extension version. Run *.py directly in the integrated terminal (not DEBUG), and the input() works fine.

@conkerkh
Copy link

Regardless "redirectOutput" settings "input" is broken on macOS Catalina and probably other versions as well.

@fabioz
Copy link
Collaborator

fabioz commented Aug 18, 2020

@int19h as a note, there's code to kill a process tree at https://github.com/microsoft/debugpy/blob/master/src/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_api.py#L975 (I don't think pydevd is even imported on the no-debug mode, so, probably the alternative so that there are no deps is copying that code and adapt it to kill a process tree -- although if pydevd can be imported, it should be possible to refactor the code a bit to have an API to kill a process tree given a pid).

@fabioz
Copy link
Collaborator

fabioz commented Aug 18, 2020

For anyone arriving here, there are currently no workarounds other then downgrading the python extension to a version below 2020.8.101144, which is the one that contains the debugger updates which introduced this issue.

This issue currently affects input() on Linux and Mac (including the case for Remote-SSH into those), while Windows appears to be unaffected.

This is a high-priority issue and it's already being worked on.

@int19h
Copy link
Contributor

int19h commented Aug 18, 2020

@fabioz Yep, the adapter never imports pydevd at all, deliberately so.

My other concern with that approach is that on Unix, walking the process tree manually and killing PIDs can potentially race with process termination & creation, so you can end up killing unrelated processes that just happened to reuse PIDs. It's exacerbated in "launch" cleanup scenario, because that one is often a race between the process terminating normally, and the launcher killing it.

And while we can manage PID lifetime for the immediate debuggee (by not doing waitpid() until it's safe for PID to be reused), we can't manage it for debuggee's subprocesses, since the code that might or might not waitpid() on them is not under our control.

@int19h
Copy link
Contributor

int19h commented Aug 18, 2020

The hacky workaround is to remove this bit in debugpy that's bundled with the extension:

if sys.platform != "win32":
# Start the debuggee in a new process group, so that the launcher can kill
# the entire process tree later.
kwargs.update(preexec_fn=os.setpgrp)

(In multi-process scenarios, this will also prevent subprocesses from being cleaned up in some cases, esp. if using Start without Debugging.)

int19h added a commit to int19h/debugpy that referenced this issue Aug 18, 2020
Make the debuggee process group the foreground group in its session.

Add a test for input(), and improve existing stdin test to cover more cases.
@SaadiSave
Copy link

So when will this fix be released?

@yousefabuz17
Copy link
Author

@SaadiSave hopefully soon but honestly I have no problem in using the roll back version. Simply downgrade python for now. Still works very fast with no issues

@SaadiSave
Copy link

SaadiSave commented Aug 19, 2020

I tried that. The API appears to be broken. It cannot find the old version. Could you send the link that you used to download the vsix for the old version?
Thank you.

@karthiknadig
Copy link
Member

You can do it from VS Code, click on the gear icon for the extension and select "install another version":
image

If you want to manually find and install older versions of the extension they can be found here: https://github.com/microsoft/vscode-python/releases

@int19h int19h closed this as completed in 5087603 Aug 19, 2020
@SaadiSave
Copy link

Thank you

@yousefabuz17
Copy link
Author

yousefabuz17 commented Aug 20, 2020

This may solve this issue for the mean time. I have not tested it out yet as it was just mentioned. Thought I'd share it to anyone here. Hope it works.

https://github.com/microsoft/vscode-python/issues/13536

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working P0 The issue is important, and should be prioritized for new work.
Projects
None yet
Development

No branches or pull requests

9 participants