Skip to content

First Run in Terminal sometimes doesn't start python REPL or wait for it to finish starting #22691

Description

@starball5

Behaviour

Expected vs. Actual

When no Python terminal created by the "Python: Run in Terminal" is currently open, running "Python: Run in Terminal" creates a new Terminal named "Python", and (tries to) start a Python interpreter to run the selected Python code in.

I expect the Python interpreter to finish starting up, and the first selected / smart-sent line to be given to the Python interpreter.

Instead, sometimes the first selected / smart-sent line becomes appended to the command that's supposed to start up the Python interpreter, resulting in an invalid command sent to the system shell. Sometimes even the first selected / smart-sent line is passed alone to the system shell before the command to start the Python interpreter has been run, and then the command to start the Python interpreter is run immediately afterward.

Steps to reproduce:

I cannot reproduce this reliably. Sometimes it starts up just fine, and sometimes I observe one of the two wrong behaviours.

I've tried using different combinations of the terminal.integrated.shellIntegration.enabled, python.terminal.activateEnvInCurrentTerminal, and python.terminal.activateEnvironment settings, but they don't seem to make a difference.

I'm on VS Code 1.85.1 on Ubuntu 22.04.2. I have v2023.23.13541005 of this Python extension installed.

Diagnostic data

  • Python version (& distribution if applicable, e.g. Anaconda): 3.10.12
  • Type of virtual environment used (e.g. conda, venv, virtualenv, etc.): Global
  • Value of the python.languageServer setting: Pylance
Output for Python in the Output panel (View→Output, change the drop-down the upper-right of the Output panel to Python)

2023-12-22 22:14:01.084 [info] Send text to terminal: /bin/python3
2023-12-22 22:14:01.969 [info] Send text to terminal: a=1
b=2
c=3

Which looks fine, but my shell receives /bin/python3a=1, gives an error message for it, then receives b=2 and c=3. It's not supposed to receive any of that (it's supposed to go to the Python interpreter, which failed to start due to the bad command).

User Settings


languageServer: "Pylance"

testing
• unittestArgs: "<placeholder>"
• unittestEnabled: true

terminal
• activateEnvironment: true (also happens when set to false)

Activity

  1. dharmatech commented on Dec 23, 2023

    @dharmatech

    Thank you for submitting the issue starball (@starball5) 👍🤝

  2. dharmatech commented on Dec 23, 2023

    @dharmatech

    Just for reference, here's where I asked about this issue on stackoverflow:

    https://stackoverflow.com/questions/77702135/f8-the-first-time-evaluates-line-in-powershell-not-in-python

    This issue occurs consistently on my system so if you have any questions or want me to try something, feel free to let me know.

    Thanks!

  3. anthonykim1 commented on Jan 3, 2024

    @anthonykim1

    Hello starball (@starball5), thanks for filing the issue. We are aware of this issue, and I will be looking closely into why this is happening. This is actually first time non-windows users filed issue with this first execution being swallowed up, but I will look in further see why it is happening and try to think of the solution.

  4. added
    bugIssue identified by VS Code Team member as probable bug
    and removed
    info-neededIssue requires more information from poster
    on Jan 3, 2024
  5. starball5 commented on Jan 4, 2024

    @starball5
    Author

    Anthony Kim (@anthonykim1) to be clear, is this labelled "info-needed" because you are waiting on me to provide further info? If so, what do I need to do?

  6. anthonykim1 commented on Jan 4, 2024

    @anthonykim1

    starball (@starball5) I think the bot automatically added it, but nothing needed from you at this point. It is currently not labelled with info-needed.

  7. anthonykim1 commented on Feb 16, 2024

    @anthonykim1

    Hello starball (@starball5)
    Good News for you: I have just merged in a PR to reduce the risk of the first command being ignored. It should be in the pre-release tomorrow if you would like to check it out!

  8. added a commit that references this issue on Feb 17, 2024
    e53651d
  9. locked as resolved and limited conversation to collaborators on Mar 18, 2024
  10. added 2 commits that reference this issue on Mar 28, 2024
    d822c25
    c976f74
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area-replbugIssue identified by VS Code Team member as probable bugtriage-neededNeeds assignment to the proper sub-team

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions