66import { ChildProcess } from 'child_process' ;
77import { inject , injectable } from 'inversify' ;
88import { IDisposable } from 'monaco-editor' ;
9- import { ObservableExecutionResult } from '../../common/process/types' ;
9+ import { IPythonExecutionService , ObservableExecutionResult } from '../../common/process/types' ;
1010import { Resource } from '../../common/types' ;
1111import { noop } from '../../common/utils/misc' ;
1212import { PythonInterpreter } from '../../pythonEnvironments/info' ;
@@ -27,15 +27,10 @@ export class PythonKernelLauncherDaemon implements IDisposable {
2727 resource : Resource ,
2828 kernelSpec : IJupyterKernelSpec ,
2929 interpreter ?: PythonInterpreter
30- ) : Promise < { observableOutput : ObservableExecutionResult < string > ; daemon : IPythonKernelDaemon } | undefined > {
30+ ) : Promise < { observableOutput : ObservableExecutionResult < string > ; daemon : IPythonKernelDaemon | undefined } > {
3131 const daemon = await this . daemonPool . get ( resource , kernelSpec , interpreter ) ;
3232
33- // The daemon pool can return back a non-IPythonKernelDaemon if daemon service is not supported or for Python 2.
34- // Use a check for the daemon.start function here before we call it.
35- if ( ! daemon . start ) {
36- return undefined ;
37- }
38-
33+ // Check to see if we have the type of kernelspec that we expect
3934 const args = kernelSpec . argv . slice ( ) ;
4035 const modulePrefixIndex = args . findIndex ( ( item ) => item === '-m' ) ;
4136 if ( modulePrefixIndex === - 1 ) {
@@ -49,11 +44,26 @@ export class PythonKernelLauncherDaemon implements IDisposable {
4944 const moduleArgs = args . slice ( modulePrefixIndex + 2 ) ;
5045 const env = kernelSpec . env && Object . keys ( kernelSpec . env ) . length > 0 ? kernelSpec . env : undefined ;
5146
52- const observableOutput = await daemon . start ( moduleName , moduleArgs , { env } ) ;
53- if ( observableOutput . proc ) {
54- this . processesToDispose . push ( observableOutput . proc ) ;
47+ // The daemon pool can return back a non-IPythonKernelDaemon if daemon service is not supported or for Python 2.
48+ // Use a check for the daemon.start function here before we call it.
49+ if ( ! daemon . start ) {
50+ // If we don't have a KernelDaemon here then we have an execution service and should use that to launch
51+ // Typing is a bit funk here, as createDaemon can return an execution service instead of the requested
52+ // daemon class
53+ // tslint:disable-next-line:no-any
54+ const executionService = ( daemon as any ) as IPythonExecutionService ;
55+
56+ const observableOutput = executionService . execModuleObservable ( moduleName , moduleArgs , { env } ) ;
57+
58+ return { observableOutput, daemon : undefined } ;
59+ } else {
60+ // In the case that we do have a kernel deamon, just return it
61+ const observableOutput = await daemon . start ( moduleName , moduleArgs , { env } ) ;
62+ if ( observableOutput . proc ) {
63+ this . processesToDispose . push ( observableOutput . proc ) ;
64+ }
65+ return { observableOutput, daemon } ;
5566 }
56- return { observableOutput, daemon } ;
5767 }
5868 public dispose ( ) {
5969 while ( this . processesToDispose . length ) {
0 commit comments