Skip to content

Commands sent to terminal gets swallowed by previous command #67693

@DonJayamanne

Description

@DonJayamanne
  • VSCode Version:Version 1.31.0-insider (1.31.0-insider)
  • OS Version:Mac

Steps to Reproduce:

  • Install latest version of Python Extension
  • Install python
  • Brew install pipenv
  • Open a folder in VSC
  • Add a python file with a simple print("Hello") statement
  • Open the terminal in VSC and type the command pipenv shell
    • This will create a virtual environment for the current folder
  • Open another terminal and notice how the Python extension will automatically add pipenv shell, causing the previously created environment to get activated in this new terminal.
  • Reload VSC
    • The above pipenv environment will now be automatically selected
    • If not, please use the command Select Python Interpreter
    • From the list, of interpreters select the interpreter with the name same as the folder name you are in.
  • Run python file in terminal
    • Open python file , right click and use the menu option Run Python file in terminal
    • The terminal will now open automatically
    • Python Extension will send the text pipenv shell to activate the environment in the terminal
    • The python extension will send the text <python interpreter> <file name> to the terminal
    • Unfortunately there's a race condition here, pipenv shell has not yet completed, and the commands sent later get swallowed up
  • End result, file doesn't run in terminal

Causes:

  • There's no way to determine when terminal has completed processing previously sent commands.
  • VSC is sending messages to the terminal, when its busy

Solutions:

  • Python extension adds a delay between the two commands being sent to the terminal (this is what we do today). However pipenv shell takes longer than other activation routines, hence we need a much longer delay (i.e. a bigger magic number), a work around.
  • Or, VSC provides some api to let us know the terminal is ready to accept input.

Related to #67692

Metadata

Metadata

Assignees

Labels

info-neededIssue requires more information from posterterminalGeneral terminal issues that don't fall under another label

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions