@@ -28,6 +28,8 @@ import {
2828} from './types' ;
2929import { isWindowsStoreInterpreter } from '../../pythonEnvironments/discovery/locators/services/windowsStoreInterpreter' ;
3030import { 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'
3335export 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