6
6
import { ChildProcess } from 'child_process' ;
7
7
import { inject , injectable } from 'inversify' ;
8
8
import { IDisposable } from 'monaco-editor' ;
9
- import { ObservableExecutionResult } from '../../common/process/types' ;
9
+ import { IPythonExecutionService , ObservableExecutionResult } from '../../common/process/types' ;
10
10
import { Resource } from '../../common/types' ;
11
11
import { noop } from '../../common/utils/misc' ;
12
12
import { PythonInterpreter } from '../../pythonEnvironments/info' ;
@@ -27,15 +27,10 @@ export class PythonKernelLauncherDaemon implements IDisposable {
27
27
resource : Resource ,
28
28
kernelSpec : IJupyterKernelSpec ,
29
29
interpreter ?: PythonInterpreter
30
- ) : Promise < { observableOutput : ObservableExecutionResult < string > ; daemon : IPythonKernelDaemon } | undefined > {
30
+ ) : Promise < { observableOutput : ObservableExecutionResult < string > ; daemon : IPythonKernelDaemon | undefined } > {
31
31
const daemon = await this . daemonPool . get ( resource , kernelSpec , interpreter ) ;
32
32
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
39
34
const args = kernelSpec . argv . slice ( ) ;
40
35
const modulePrefixIndex = args . findIndex ( ( item ) => item === '-m' ) ;
41
36
if ( modulePrefixIndex === - 1 ) {
@@ -49,11 +44,26 @@ export class PythonKernelLauncherDaemon implements IDisposable {
49
44
const moduleArgs = args . slice ( modulePrefixIndex + 2 ) ;
50
45
const env = kernelSpec . env && Object . keys ( kernelSpec . env ) . length > 0 ? kernelSpec . env : undefined ;
51
46
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 } ;
55
66
}
56
- return { observableOutput, daemon } ;
57
67
}
58
68
public dispose ( ) {
59
69
while ( this . processesToDispose . length ) {
0 commit comments