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

Console: Shell commands cannot accept user input in Python consoles #696

Open
seeM opened this issue Jun 7, 2023 · 5 comments
Open

Console: Shell commands cannot accept user input in Python consoles #696

seeM opened this issue Jun 7, 2023 · 5 comments
Labels
area: console Issues related to Console category. bug Something isn't working lang: python
Milestone

Comments

@seeM
Copy link
Contributor

seeM commented Jun 7, 2023

I encountered this when trying to do pip uninstall ipdb which requires me to enter Y, but I'm unable to:

>>> pip uninstall ipdb
Found existing installation: ipdb 0.13.13
Uninstalling ipdb-0.13.13:
  Would remove:
    /Users/seem/.pyenv/versions/3.10.11/envs/codal/bin/ipdb3
    /Users/seem/.pyenv/versions/3.10.11/envs/codal/lib/python3.10/site-packages/ipdb-0.13.13.dist-info/*
    /Users/seem/.pyenv/versions/3.10.11/envs/codal/lib/python3.10/site-packages/ipdb/*
Proceed (Y/n)?

A simpler example is:

>>> !read

which has the same issue.

Both of these work in IPython.

Might be related to #284?

@seeM seeM added the bug Something isn't working label Jun 7, 2023
@wesm wesm added area: console Issues related to Console category. bug Something isn't working and removed bug Something isn't working labels Feb 29, 2024
@seeM seeM removed their assignment Mar 8, 2024
@nstrayer
Copy link
Contributor

nstrayer commented Mar 18, 2024

Can recreate with the pip uninstall workflow.
print(input("Type something: ")) works just fine so it's purely shell commands.

@nstrayer nstrayer self-assigned this Mar 18, 2024
@nstrayer
Copy link
Contributor

image When the shell command is looking for an input, React is rendering the line as the `` component instead of `` like it does with native python input.

@jmcphers
Copy link
Collaborator

The thing that makes this hard is that the "awaiting user input" state is difficult to detect in child processes. From the perspective of the Python kernel, the pip command emitted some output, and then stopped emitting output for a while. How can we know that it's blocked waiting for stdin input and we need Positron to supply it?

This only works in IPython by accident; IPython doesn't do anything special other than (correctly) forward stuff you type while a child process is active to the child process's stdin. There's no mechanism for doing that in Positron.

One way to fix this would be to make the IPython kernel try to detect that there's a prompt active and ask Positron to supply input for the prompt (using the normal prompt input flow over the stdin socket).

Another approach, which would be more expensive but probably more correct, would be to alert Positron to the fact that a subprocess is active; in this mode, the Console would just toss all user input over to the kernel to be fed as stdin to the child process. Then we wouldn't have to detect a prompt.

@seeM
Copy link
Contributor Author

seeM commented Mar 20, 2024

This is also present in Jupyter Lab and VSCode notebooks. Adding some more context to Jonathan's diagnosis:

Here's the issue currently tracking this for Jupyter Lab: jupyterlab/jupyterlab#14041.

Here's a really old issue that tracked this in IPython but was accidentally closed in a repo reorg: ipython/ipython#514.

Here's an issue in the third party bash_kernel project that has a useful discussion: takluyver/bash_kernel#113.

@juliasilge
Copy link
Contributor

If this is something that Jupyter Lab and VS Code also have not fixed as of today, I would like to vote for moving this to the Future milestone and we wait to see the best way to address it further down the line.

@nstrayer nstrayer removed their assignment Apr 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: console Issues related to Console category. bug Something isn't working lang: python
Projects
None yet
Development

No branches or pull requests

6 participants