Skip to content

Commit a62bd99

Browse files
author
Kartik Raj
authored
Fix hang caused by loop in getting interpreter information (#17484)
* Fix hang caused by loop in getting interpreter information * News entry * Revert "Fix hang caused by loop in getting interpreter information" This reverts commit b969058. * If options.pythonPath is set, do not block on autoselection
1 parent 688213e commit a62bd99

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

news/2 Fixes/17484.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix hang caused by loop in getting interpreter information.

src/client/common/process/pythonExecutionFactory.ts

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import {
2828
} from './types';
2929
import { isWindowsStoreInterpreter } from '../../pythonEnvironments/discovery/locators/services/windowsStoreInterpreter';
3030
import { IInterpreterAutoSelectionService } from '../../interpreter/autoSelection/types';
31+
import { sleep } from '../utils/async';
32+
import { traceError } from '../logger';
3133

3234
// Minimum version number of conda required to be able to use 'conda run'
3335
export const CONDA_RUN_VERSION = '4.6.0';
@@ -59,13 +61,29 @@ export class PythonExecutionFactory implements IPythonExecutionFactory {
5961
}
6062

6163
public async create(options: ExecutionFactoryCreationOptions): Promise<IPythonExecutionService> {
62-
const interpreterPath = this.interpreterPathExpHelper.get(options.resource);
63-
if (!interpreterPath || interpreterPath === 'python') {
64-
await this.autoSelection.autoSelectInterpreter(options.resource); // Block on this only if no interpreter selected.
64+
let { pythonPath } = options;
65+
if (!pythonPath) {
66+
// If python path wasn't passed in, we need to auto select it and then read it
67+
// from the configuration.
68+
const interpreterPath = this.interpreterPathExpHelper.get(options.resource);
69+
if (!interpreterPath || interpreterPath === 'python') {
70+
// Block on autoselection if no interpreter selected.
71+
// Note autoselection blocks on discovery, so we do not want discovery component
72+
// to block on this code. Discovery component should 'options.pythonPath' before
73+
// calling into this, so this scenario should not happen. But in case consumer
74+
// makes such an error. So break the loop via timeout and log error.
75+
const success = await Promise.race([
76+
this.autoSelection.autoSelectInterpreter(options.resource).then(() => true),
77+
sleep(50000).then(() => false),
78+
]);
79+
if (!success) {
80+
traceError(
81+
'Autoselection timeout out, this is likely a issue with how consumer called execution factory API. Using default python to execute.',
82+
);
83+
}
84+
}
6585
}
66-
const pythonPath = options.pythonPath
67-
? options.pythonPath
68-
: this.configService.getSettings(options.resource).pythonPath;
86+
pythonPath = this.configService.getSettings(options.resource).pythonPath;
6987
const processService: IProcessService = await this.processServiceFactory.create(options.resource);
7088
processService.on('exec', this.logger.logProcess.bind(this.logger));
7189

0 commit comments

Comments
 (0)