@@ -101,7 +101,7 @@ export function execPythonFile(file: string, args: string[], cwd: string, includ
101101 if ( stdOut ) {
102102 return spawnFileInternal ( file , args , { cwd } , includeErrorAsResponse , stdOut , token ) ;
103103 }
104- return execFileInternal ( file , args , { cwd : cwd } , includeErrorAsResponse ) ;
104+ return execFileInternal ( file , args , { cwd : cwd } , includeErrorAsResponse , token ) ;
105105 }
106106
107107 return getPythonInterpreterDirectory ( ) . then ( pyPath => {
@@ -110,7 +110,7 @@ export function execPythonFile(file: string, args: string[], cwd: string, includ
110110 if ( stdOut ) {
111111 return spawnFileInternal ( file , args , { cwd } , includeErrorAsResponse , stdOut , token ) ;
112112 }
113- return execFileInternal ( file , args , { cwd : cwd } , includeErrorAsResponse ) ;
113+ return execFileInternal ( file , args , { cwd : cwd } , includeErrorAsResponse , token ) ;
114114 }
115115
116116 if ( customEnvVariables === null ) {
@@ -134,7 +134,7 @@ export function execPythonFile(file: string, args: string[], cwd: string, includ
134134 if ( stdOut ) {
135135 return spawnFileInternal ( file , args , { cwd, env : customEnvVariables } , includeErrorAsResponse , stdOut , token ) ;
136136 }
137- return execFileInternal ( file , args , { cwd, env : customEnvVariables } , includeErrorAsResponse ) ;
137+ return execFileInternal ( file , args , { cwd, env : customEnvVariables } , includeErrorAsResponse , token ) ;
138138 } ) ;
139139}
140140
@@ -160,11 +160,19 @@ function handleResponse(file: string, includeErrorAsResponse: boolean, error: Er
160160 resolve ( stdout + '' ) ;
161161 } ) ;
162162}
163- function execFileInternal ( file : string , args : string [ ] , options : child_process . ExecFileOptions , includeErrorAsResponse : boolean ) : Promise < string > {
163+ function execFileInternal ( file : string , args : string [ ] , options : child_process . ExecFileOptions , includeErrorAsResponse : boolean , token ?: CancellationToken ) : Promise < string > {
164164 return new Promise < string > ( ( resolve , reject ) => {
165- child_process . execFile ( file , args , options , ( error , stdout , stderr ) => {
165+ let proc = child_process . execFile ( file , args , options , ( error , stdout , stderr ) => {
166166 handleResponse ( file , includeErrorAsResponse , error , stdout , stderr ) . then ( resolve , reject ) ;
167167 } ) ;
168+ if ( token && token . onCancellationRequested ) {
169+ token . onCancellationRequested ( ( ) => {
170+ if ( proc ) {
171+ proc . kill ( ) ;
172+ proc = null ;
173+ }
174+ } ) ;
175+ }
168176 } ) ;
169177}
170178function spawnFileInternal ( file : string , args : string [ ] , options : child_process . ExecFileOptions , includeErrorAsResponse : boolean , stdOut : ( line : string ) => void , token ?: CancellationToken ) : Promise < string > {
0 commit comments