11import * as cp from 'child_process' ;
2- import { PythonEnvironment , PythonBackgroundRunOptions , PythonProcess } from '../../api' ;
2+ import { PythonBackgroundRunOptions , PythonEnvironment , PythonProcess } from '../../api' ;
3+ import { traceError , traceInfo } from '../../common/logging' ;
34
45export async function runInBackground (
56 environment : PythonEnvironment ,
@@ -9,6 +10,7 @@ export async function runInBackground(
910 environment . execInfo ?. activatedRun ?. executable ?? environment . execInfo ?. run . executable ?? 'python' ;
1011 const args = environment . execInfo ?. activatedRun ?. args ?? environment . execInfo ?. run . args ?? [ ] ;
1112 const allArgs = [ ...args , ...options . args ] ;
13+ traceInfo ( `Running in background: ${ executable } ${ allArgs . join ( ' ' ) } ` ) ;
1214
1315 const proc = cp . spawn ( executable , allArgs , { stdio : 'pipe' , cwd : options . cwd , env : options . env } ) ;
1416
@@ -22,8 +24,17 @@ export async function runInBackground(
2224 proc . kill ( ) ;
2325 }
2426 } ,
25- onExit : ( listener : ( code : number | null , signal : NodeJS . Signals | null ) => void ) => {
26- proc . on ( 'exit' , listener ) ;
27+ onExit : ( listener : ( code : number | null , signal : NodeJS . Signals | null , error ?: Error | null ) => void ) => {
28+ proc . on ( 'exit' , ( code , signal ) => {
29+ if ( code && code !== 0 ) {
30+ traceError ( `Process exited with error code: ${ code } , signal: ${ signal } ` ) ;
31+ }
32+ listener ( code , signal , null ) ;
33+ } ) ;
34+ proc . on ( 'error' , ( error ) => {
35+ traceError ( `Process error: ${ error ?. message || error } ${ error ?. stack ? '\n' + error . stack : '' } ` ) ;
36+ listener ( null , null , error ) ;
37+ } ) ;
2738 } ,
2839 } ;
2940}
0 commit comments