From 2e8dc67455ed779eddab6a609601026f763b6803 Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Mon, 17 Jul 2023 13:55:15 -0700 Subject: [PATCH] Add extra logging regarding interpreter discovery (#21639) For https://github.com/microsoft/vscode-python/issues/21310 --- src/client/common/process/rawProcessApis.ts | 4 +++- src/client/common/utils/async.ts | 6 ++++++ .../base/locators/lowLevel/activeStateLocator.ts | 1 + .../base/locators/lowLevel/microsoftStoreLocator.ts | 1 + .../base/locators/lowLevel/posixKnownPathsLocator.ts | 1 + .../base/locators/lowLevel/pyenvLocator.ts | 1 + .../base/locators/lowLevel/windowsKnownPathsLocator.ts | 1 + .../base/locators/lowLevel/windowsRegistryLocator.ts | 1 + 8 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/client/common/process/rawProcessApis.ts b/src/client/common/process/rawProcessApis.ts index 025e5b607229..6f3e40d68736 100644 --- a/src/client/common/process/rawProcessApis.ts +++ b/src/client/common/process/rawProcessApis.ts @@ -100,7 +100,7 @@ export function plainExec( const deferred = createDeferred>(); const disposable: IDisposable = { dispose: () => { - if (!proc.killed && !deferred.completed) { + if (!proc.killed) { proc.kill(); } }, @@ -156,10 +156,12 @@ export function plainExec( deferred.resolve({ stdout, stderr }); } internalDisposables.forEach((d) => d.dispose()); + disposable.dispose(); }); proc.once('error', (ex) => { deferred.reject(ex); internalDisposables.forEach((d) => d.dispose()); + disposable.dispose(); }); return deferred.promise; diff --git a/src/client/common/utils/async.ts b/src/client/common/utils/async.ts index 29bf4a8d6fca..5905399cd4a1 100644 --- a/src/client/common/utils/async.ts +++ b/src/client/common/utils/async.ts @@ -50,11 +50,17 @@ class DeferredImpl implements Deferred { } public resolve(_value: T | PromiseLike) { + if (this.completed) { + return; + } this._resolve.apply(this.scope ? this.scope : this, [_value]); this._resolved = true; } public reject(_reason?: string | Error | Record) { + if (this.completed) { + return; + } this._reject.apply(this.scope ? this.scope : this, [_reason]); this._rejected = true; } diff --git a/src/client/pythonEnvironments/base/locators/lowLevel/activeStateLocator.ts b/src/client/pythonEnvironments/base/locators/lowLevel/activeStateLocator.ts index 987abf4f4157..dc507b9c94bd 100644 --- a/src/client/pythonEnvironments/base/locators/lowLevel/activeStateLocator.ts +++ b/src/client/pythonEnvironments/base/locators/lowLevel/activeStateLocator.ts @@ -20,6 +20,7 @@ export class ActiveStateLocator extends LazyResourceBasedLocator { traceVerbose(`Couldn't locate the state binary.`); return; } + traceVerbose(`Searching for active state environments`); const projects = await state.getProjects(); if (projects === undefined) { traceVerbose(`Couldn't fetch State Tool projects.`); diff --git a/src/client/pythonEnvironments/base/locators/lowLevel/microsoftStoreLocator.ts b/src/client/pythonEnvironments/base/locators/lowLevel/microsoftStoreLocator.ts index 9b5283f7f967..7adeeae89858 100644 --- a/src/client/pythonEnvironments/base/locators/lowLevel/microsoftStoreLocator.ts +++ b/src/client/pythonEnvironments/base/locators/lowLevel/microsoftStoreLocator.ts @@ -87,6 +87,7 @@ export class MicrosoftStoreLocator extends FSWatchingLocator { protected doIterEnvs(): IPythonEnvsIterator { const iterator = async function* (kind: PythonEnvKind) { + traceVerbose('Searching for windows store envs'); const exes = await getMicrosoftStorePythonExes(); yield* exes.map(async (executablePath: string) => ({ kind, diff --git a/src/client/pythonEnvironments/base/locators/lowLevel/posixKnownPathsLocator.ts b/src/client/pythonEnvironments/base/locators/lowLevel/posixKnownPathsLocator.ts index 97726307c573..2e4e2dc13e61 100644 --- a/src/client/pythonEnvironments/base/locators/lowLevel/posixKnownPathsLocator.ts +++ b/src/client/pythonEnvironments/base/locators/lowLevel/posixKnownPathsLocator.ts @@ -26,6 +26,7 @@ export class PosixKnownPathsLocator extends Locator { } const iterator = async function* (kind: PythonEnvKind) { + traceVerbose('Searching for interpreters in posix paths locator'); // Filter out pyenv shims. They are not actual python binaries, they are used to launch // the binaries specified in .python-version file in the cwd. We should not be reporting // those binaries as environments. diff --git a/src/client/pythonEnvironments/base/locators/lowLevel/pyenvLocator.ts b/src/client/pythonEnvironments/base/locators/lowLevel/pyenvLocator.ts index dc3290c9993c..4fd1891a179c 100644 --- a/src/client/pythonEnvironments/base/locators/lowLevel/pyenvLocator.ts +++ b/src/client/pythonEnvironments/base/locators/lowLevel/pyenvLocator.ts @@ -16,6 +16,7 @@ import { traceError, traceVerbose } from '../../../../logging'; * all the environments (global or virtual) in that directory. */ async function* getPyenvEnvironments(): AsyncIterableIterator { + traceVerbose('Searching for pyenv environments'); const pyenvVersionDir = getPyenvVersionsDir(); const subDirs = getSubDirs(pyenvVersionDir, { resolveSymlinks: true }); diff --git a/src/client/pythonEnvironments/base/locators/lowLevel/windowsKnownPathsLocator.ts b/src/client/pythonEnvironments/base/locators/lowLevel/windowsKnownPathsLocator.ts index 377b1117b858..337a8fb09a97 100644 --- a/src/client/pythonEnvironments/base/locators/lowLevel/windowsKnownPathsLocator.ts +++ b/src/client/pythonEnvironments/base/locators/lowLevel/windowsKnownPathsLocator.ts @@ -93,6 +93,7 @@ function getDirFilesLocator( // rather than in each low-level locator. In the meantime we // take a naive approach. async function* iterEnvs(query: PythonLocatorQuery): IPythonEnvsIterator { + traceVerbose('Searching for windows path interpreters'); yield* await getEnvs(locator.iterEnvs(query)); traceVerbose('Finished searching for windows path interpreters'); } diff --git a/src/client/pythonEnvironments/base/locators/lowLevel/windowsRegistryLocator.ts b/src/client/pythonEnvironments/base/locators/lowLevel/windowsRegistryLocator.ts index 954d1bfd2a41..b52e9c35779f 100644 --- a/src/client/pythonEnvironments/base/locators/lowLevel/windowsRegistryLocator.ts +++ b/src/client/pythonEnvironments/base/locators/lowLevel/windowsRegistryLocator.ts @@ -14,6 +14,7 @@ export class WindowsRegistryLocator extends Locator { // eslint-disable-next-line class-methods-use-this public iterEnvs(): IPythonEnvsIterator { const iterator = async function* () { + traceVerbose('Searching for windows registry interpreters'); const interpreters = await getRegistryInterpreters(); for (const interpreter of interpreters) { try {