Skip to content

Commit 87d2ecc

Browse files
author
Kartik Raj
committed
Add caching and relax valid executable check
1 parent c765836 commit 87d2ecc

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/client/common/process/pythonEnvironment.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ import { getExecutablePath } from '../../pythonEnvironments/info/executable';
88
import { getInterpreterInfo } from '../../pythonEnvironments/info/interpreter';
99
import { traceError, traceInfo } from '../logger';
1010
import { IFileSystem } from '../platform/types';
11+
import { createDeferred, Deferred } from '../utils/async';
1112
import * as internalPython from './internal/python';
1213
import { ExecutionResult, IProcessService, ShellOptions, SpawnOptions } from './types';
1314

15+
const cachedExecutablePath: Map<string, Deferred<string>> = new Map<string, Deferred<string>>();
1416
class PythonEnvironment {
1517
private cachedInterpreterInformation: InterpreterInformation | undefined | null = null;
1618

@@ -49,8 +51,18 @@ class PythonEnvironment {
4951
if (await this.deps.isValidExecutable(this.pythonPath)) {
5052
return this.pythonPath;
5153
}
54+
const result = cachedExecutablePath.get(this.pythonPath);
55+
if (result !== undefined) {
56+
// Another call for this environment has already been made, return its result
57+
return result.promise;
58+
}
59+
const deferred = createDeferred<string>();
60+
cachedExecutablePath.set(this.pythonPath, deferred);
5261
const python = this.getExecutionInfo();
53-
return getExecutablePath(python, this.deps.exec);
62+
return getExecutablePath(python, this.deps.exec).then((r) => {
63+
deferred.resolve(r);
64+
return r;
65+
});
5466
}
5567

5668
public async getModuleVersion(moduleName: string): Promise<string | undefined> {
@@ -139,7 +151,7 @@ export function createCondaEnv(
139151
}
140152
const pythonArgv = [condaFile, ...runArgs, 'python'];
141153
const deps = createDeps(
142-
async (filename) => fs.fileExists(filename),
154+
async (filename) => fs.pathExists(filename),
143155
pythonArgv,
144156

145157
// TODO: Use pythonArgv here once 'conda run' can be

0 commit comments

Comments
 (0)