Skip to content

Commit 487afe8

Browse files
author
Kartik Raj
committed
Use worker threads for fetching conda environments
1 parent 384e56a commit 487afe8

File tree

5 files changed

+22
-20
lines changed

5 files changed

+22
-20
lines changed

src/client/common/process/worker/plainExecWorker.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import { parentPort, workerData } from 'worker_threads';
2-
import { workerPlainExec } from './workerRawProcessApis';
2+
import { _workerPlainExecImpl } from './workerRawProcessApis';
33

4-
workerPlainExec(workerData.file, workerData.args, workerData.options, workerData.defaultEnv, workerData.disposables)
4+
_workerPlainExecImpl(
5+
workerData.file,
6+
workerData.args,
7+
workerData.options,
8+
workerData.defaultEnv,
9+
workerData.disposables,
10+
)
511
.then((res) => {
612
if (!parentPort) {
713
throw new Error('Not in a worker thread');

src/client/common/process/worker/rawProcessApiWrapper.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,27 @@ import * as path from 'path';
66
import { WorkspaceService } from '../../application/workspace';
77
import { ProcessLogger } from '../logger';
88
import { executeWorkerFile } from './main';
9-
import { EnvironmentVariables, ExecutionResult, IDisposable, ShellOptions } from './types';
9+
import { EnvironmentVariables, ExecutionResult, ShellOptions } from './types';
1010

11-
export function shellExec(
11+
export function workerShellExec(
1212
command: string,
1313
options: ShellOptions,
1414
defaultEnv?: EnvironmentVariables,
15-
disposables?: Set<IDisposable>,
1615
): Promise<ExecutionResult<string>> {
1716
const processLogger = new ProcessLogger(new WorkspaceService());
1817
processLogger.logProcess(command, undefined, options);
1918
return executeWorkerFile(path.join(__dirname, 'shellExecWorker.js'), {
2019
command,
2120
options,
2221
defaultEnv,
23-
disposables,
2422
});
2523
}
2624

27-
export function plainExec(
25+
export function workerPlainExec(
2826
file: string,
2927
args: string[],
3028
options: SpawnOptions & { doNotLog?: boolean } = {},
3129
defaultEnv?: EnvironmentVariables,
32-
disposables?: Set<IDisposable>,
3330
): Promise<ExecutionResult<string>> {
3431
const processLogger = new ProcessLogger(new WorkspaceService());
3532
processLogger.logProcess(file, args, options);
@@ -38,6 +35,5 @@ export function plainExec(
3835
args,
3936
options,
4037
defaultEnv,
41-
disposables,
4238
});
4339
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import { parentPort, workerData } from 'worker_threads';
2-
import { workerShellExec } from './workerRawProcessApis';
2+
import { _workerShellExecImpl } from './workerRawProcessApis';
33

4-
workerShellExec(workerData.command, workerData.options, workerData.defaultEnv, workerData.disposables)
4+
_workerShellExecImpl(workerData.command, workerData.options, workerData.defaultEnv, workerData.disposables)
55
.then((res) => {
66
if (!parentPort) {
77
throw new Error('Not in a worker thread');
88
}
9-
parentPort.postMessage(res);
9+
parentPort.postMessage({ res });
1010
})
1111
.catch((ex) => {
1212
if (!parentPort) {
1313
throw new Error('Not in a worker thread');
1414
}
15-
parentPort.postMessage(ex);
15+
parentPort.postMessage({ ex });
1616
});

src/client/common/process/worker/workerRawProcessApis.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ function getDefaultOptions<T extends ShellOptions | SpawnOptions>(options: T, de
5252
return defaultOptions;
5353
}
5454

55-
export function workerShellExec(
55+
export function _workerShellExecImpl(
5656
command: string,
5757
options: ShellOptions,
5858
defaultEnv?: EnvironmentVariables,
@@ -102,7 +102,7 @@ export function workerShellExec(
102102
});
103103
}
104104

105-
export function workerPlainExec(
105+
export function _workerPlainExecImpl(
106106
file: string,
107107
args: string[],
108108
options: SpawnOptions & { doNotLog?: boolean } = {},

src/client/pythonEnvironments/common/externalDependencies.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { getOSType, OSType } from '../../common/utils/platform';
1212
import { IServiceContainer } from '../../ioc/types';
1313
import { traceError, traceVerbose } from '../../logging';
1414
import { DiscoveryUsingWorkers } from '../../common/experiments/groups';
15-
import { plainExec, shellExec } from '../../common/process/worker/rawProcessApiWrapper';
15+
import { workerPlainExec, workerShellExec } from '../../common/process/worker/rawProcessApiWrapper';
1616
import { IEnvironmentVariablesProvider } from '../../common/variables/types';
1717

1818
let internalServiceContainer: IServiceContainer;
@@ -23,25 +23,25 @@ export function initializeExternalDependencies(serviceContainer: IServiceContain
2323
// processes
2424

2525
export async function shellExecute(command: string, options: ShellOptions = {}): Promise<ExecutionResult<string>> {
26-
if (inExperiment(DiscoveryUsingWorkers.experiment)) {
26+
if (!inExperiment(DiscoveryUsingWorkers.experiment)) {
2727
const service = await internalServiceContainer.get<IProcessServiceFactory>(IProcessServiceFactory).create();
2828
return service.shellExec(command, options);
2929
}
3030
const envVarsService = internalServiceContainer.get<IEnvironmentVariablesProvider>(IEnvironmentVariablesProvider);
3131
const envs = await envVarsService.getEnvironmentVariables();
3232
options.env = { ...options.env, ...envs };
33-
return shellExec(command, options);
33+
return workerShellExec(command, options);
3434
}
3535

3636
export async function exec(file: string, args: string[], options: SpawnOptions = {}): Promise<ExecutionResult<string>> {
37-
if (inExperiment(DiscoveryUsingWorkers.experiment)) {
37+
if (!inExperiment(DiscoveryUsingWorkers.experiment)) {
3838
const service = await internalServiceContainer.get<IProcessServiceFactory>(IProcessServiceFactory).create();
3939
return service.exec(file, args, options);
4040
}
4141
const envVarsService = internalServiceContainer.get<IEnvironmentVariablesProvider>(IEnvironmentVariablesProvider);
4242
const envs = await envVarsService.getEnvironmentVariables();
4343
options.env = { ...options.env, ...envs };
44-
return plainExec(file, args, options);
44+
return workerPlainExec(file, args, options);
4545
}
4646

4747
export function inExperiment(experimentName: string): boolean {

0 commit comments

Comments
 (0)