Skip to content

Debugger commands sent to terminal get swallowed by previous terminal command #67692

Closed

Description

  • 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.
  • Debug the python file
    • The terminal will now open automatically
    • Python Extension will send the text pipenv shell to activate the environment in the terminal
    • VSC Debugger sends the necessary commands to the terminal
    • Unfortunately there's a race condition here, pipenv shell has not yet completed, and the commands sent by VSC debugger get swallowed up
  • End result, debugger doesn't start

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:

  1. Python extension can take complete control of opening terminals, etc and not use runInTerminal request (i.e. python extension re-invent the wheel).
  2. VSC DAP accepts additional commands that need to be invokved in the runInTerminal request.
    Currently we can only send args, how about extending this to send commands as well.
    This way the extension can send some custom commands that need to be executed before the VSC debugger commands. I.e. chain them together.

Activity

  1. added
    terminalGeneral terminal issues that don't fall under another label
    on Jan 31, 2019
  2. Tyriar commented on Feb 1, 2019

    @Tyriar
    Contributor
  3. removed
    terminalGeneral terminal issues that don't fall under another label
    on Feb 1, 2019
  4. added
    debugDebug viewlet, configurations, breakpoints, adapter issues
    bugIssue identified by VS Code Team member as probable bug
    on May 20, 2019
  5. added this to the June 2019 milestone on Jun 7, 2019
  6. brettcannon commented on Jul 9, 2019

    @brettcannon
    Member

    To help kickstart this again, the two ideas we had today for solving our debugger issues (if you all would be so gracious as to implement one of them 😉 ) are:

    1. Provide a way for us to specify the terminal ID to have the debugger run into (so we can make sure the terminal is already activated for the Python virtual environment)
    2. Open up an API to the code that constructs the command that gets sent into the terminal (so we can dynamically construct a shell script of two lines -- one to activate, one to run the debugger - so everything is quoted appropriately in the shell script and then we have the terminal run the shell script to make sure everything completes appropriately serially)
  7. Tyriar commented on Jul 10, 2019

    @Tyriar
    Contributor

    I haven't really looked into DAP much, but I had a look at how runInTerminal works. You might be able to pass in this as the first arg in the args array to string together multiple commands?

    • Linux/macOS: sh -c "pipenv shell && debug"
    • Windows: cmd.exe /k ... or equivalent in PS

    Also created #77110 and #77111 after looking into the feature.

  8. brettcannon commented on Jul 10, 2019

    @brettcannon
    Member

    Will that quote what's in those quotes correctly? E.g. if one of the args that you need has a space will that get quoted appropriately in that string you pass to sh?

  9. Tyriar commented on Jul 10, 2019

    @Tyriar
    Contributor

    Brett Cannon (@brettcannon) provided the quotes get escaped correctly in debug I would think so.

  10. weinand commented on Jul 26, 2019

    @weinand
    Contributor

    I've fixed issues #77110 and #77111, but they don't really help with the issue at hand.

    As Daniel Imms (@Tyriar) has pointed out in #67693 (comment), there is not much we can do here. His recommendation in #67692 (comment) is the way to go.

    Quoting should work fine; if not, please file separate issues for them.

  11. removed
    bugIssue identified by VS Code Team member as probable bug
    on Jul 26, 2019
  12. removed this from the July 2019 milestone on Jul 26, 2019
  13. locked and limited conversation to collaborators on Sep 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

*as-designedDescribed behavior is as designeddebugDebug viewlet, configurations, breakpoints, adapter issues

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions