Skip to content

Python commands are printed twice in the output channel #7160

Closed

Description

Environment data

  • VS Code version: 1.37.1
  • Extension version (available under the Extensions sidebar): master 39cf9e0
  • OS and version: macOS Mojave 10.14.6

Expected behaviour

Python commands should only be displayed once in the "Python" output channel.

Actual behaviour

Some Python commands (for example linting or formatting) are displayed twice.

Steps to reproduce:

  1. Start debugging the extension
  2. Open a python file and enable linting or formatting on save
  3. Set 2 breakpoints:
  4. Save the file
  5. Notice that this.emit('exec', file, args, options); is only hit once, but the debugger stops twice onlogger.logProcess().

Cause

We register 2 'exec' listeners to the python process:

  • In the create or createActivatedEnvironment method in PythonExecutionFactory:
    public async create(options: ExecutionFactoryCreationOptions): Promise<IPythonExecutionService> {
    const pythonPath = options.pythonPath ? options.pythonPath : this.configService.getSettings(options.resource).pythonPath;
    const processService: IProcessService = await this.processServiceFactory.create(options.resource);
    const processLogger = this.serviceContainer.get<IProcessLogger>(IProcessLogger);
    processService.on('exec', processLogger.logProcess.bind(processLogger));
    return new PythonExecutionService(this.serviceContainer, processService, pythonPath);
    }
  • But also in the call to await this.processServiceFactory.create:
    public async create(resource?: Uri): Promise<IProcessService> {
    const customEnvVars = await this.envVarsService.getEnvironmentVariables(resource);
    const proc: IProcessService = new ProcessService(this.decoder, customEnvVars);
    this.disposableRegistry.push(proc);
    return proc.on('exec', this.processLogger.logProcess.bind(this.processLogger));
    }

Activity

  1. ghost removed
    triage-neededNeeds assignment to the proper sub-team
    on Aug 30, 2019
  2. kbd commented on Jul 20, 2021

    @kbd

    As an easy-to-reproduce example of this, when I use "Format Document", the Python output log appears to show that Black is run twice:

    ~/.../.venv/bin/python -m black --diff --quiet ~/.../src/app/views.py.c64f5302f131d47a9d9da0861e28ac43.tmp
    cwd: ~/...
    ~/.../.venv/bin/python -m black --diff --quiet ~/.../src/app/views.py.c64f5302f131d47a9d9da0861e28ac43.tmp
    cwd: ~/...

  3. DanielNoord commented on Aug 5, 2021

    @DanielNoord

    Is there anything we can provide to get this issue some traction? I am mainly interested in whether commands are actually ran twice (which it seems it does). I'll gladly perform any tests or work with somebody to get this issue fixed!

  4. kimadeline commented on Aug 9, 2021

    @kimadeline
    Author

    Hi Daniël van Noord (@DanielNoord), if this issue gets more upvotes it'll help us prioritize it.

    I am mainly interested in whether commands are actually ran twice (which it seems it does)

    They are not, it is just the logger being called twice.

  5. karrtikr commented on Oct 25, 2021

    @karrtikr

    Verification steps:

    • Install latest extension using Python: Switch to Insiders command.
    • Open a workspace containing a python file, and open the file to activate the extension.
    • Create a new virtual environment: python -m venv .venv and select it as a interpreter using Python: Select Interpreter command.
    • Run Format document on a python file.
    • Follow prompt to install the formatter and attempt formatting again.
    • Ensure something similar to the following command:
    "~\OneDrive - Microsoft\Desktop\folders\newone\.venv\Scripts\python.exe" -m autopep8 --diff "~\OneDrive - Microsoft\Desktop\folders\newone\s.py"
    cwd: ~\OneDrive - Microsoft\Desktop\folders\newone
    

    only appears once in the output panel.

  6. DanielNoord commented on Oct 25, 2021

    @DanielNoord

    Kartik Raj (@karrtikr) Does this mean this was not fixed? Or is this just a reproduction for future reference?

  7. karrtikr commented on Oct 25, 2021

    @karrtikr

    This was fixed by me, but it has to be verified by someone else (in the team or by the users) before we consider it as done, which is why I left the steps. You're welcome to test it as well.

  8. rchiodo commented on Oct 27, 2021

    @rchiodo

    Kartik Raj (@karrtikr), Not sure if this is working or not?

    I get this:

    image

    Looks like it logs twice?

  9. karrtikr commented on Oct 27, 2021

    @karrtikr

    Can you turn off verbose logging and see if it logs twice? Verbose can log anything.

  10. rchiodo commented on Oct 27, 2021

    @rchiodo

    Yep that was it. Only logs once without verbose.

  11. locked as resolved and limited conversation to collaborators on Nov 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area-editor-*User-facing catch-allbugIssue identified by VS Code Team member as probable buggood first issueverification-neededVerification of issue is requestedverifiedVerification succeeded

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions