@@ -7,7 +7,6 @@ import * as tcpPortUsed from 'tcp-port-used';
7
7
import { Event , EventEmitter } from 'vscode' ;
8
8
import { PYTHON_LANGUAGE } from '../../common/constants' ;
9
9
import { traceError , traceInfo , traceWarning } from '../../common/logger' ;
10
- import { IFileSystem , TemporaryFile } from '../../common/platform/types' ;
11
10
import { IProcessServiceFactory , ObservableExecutionResult } from '../../common/process/types' ;
12
11
import { Resource } from '../../common/types' ;
13
12
import { noop , swallowExceptions } from '../../common/utils/misc' ;
@@ -39,7 +38,6 @@ export class KernelProcess implements IKernelProcess {
39
38
return this . kernelSpec . language . toLowerCase ( ) === PYTHON_LANGUAGE . toLowerCase ( ) ;
40
39
}
41
40
private _process ?: ChildProcess ;
42
- private connectionFile ?: TemporaryFile ;
43
41
private exitEvent = new EventEmitter < { exitCode ?: number ; reason ?: string } > ( ) ;
44
42
private pythonKernelLauncher ?: PythonKernelLauncherDaemon ;
45
43
private launchedOnce ?: boolean ;
@@ -49,7 +47,6 @@ export class KernelProcess implements IKernelProcess {
49
47
private readonly originalKernelSpec : IJupyterKernelSpec ;
50
48
constructor (
51
49
private readonly processExecutionFactory : IProcessServiceFactory ,
52
- private readonly file : IFileSystem ,
53
50
private readonly daemonPool : KernelDaemonPool ,
54
51
private readonly _connection : IKernelConnection ,
55
52
kernelSpec : IJupyterKernelSpec ,
@@ -72,7 +69,8 @@ export class KernelProcess implements IKernelProcess {
72
69
}
73
70
this . launchedOnce = true ;
74
71
75
- await this . createAndUpdateConnectionFile ( ) ;
72
+ // Update our connection arguments in the kernel spec
73
+ this . updateConnectionArgs ( ) ;
76
74
77
75
const exeObs = await this . launchAsObservable ( ) ;
78
76
@@ -127,7 +125,6 @@ export class KernelProcess implements IKernelProcess {
127
125
this . exitEvent . fire ( ) ;
128
126
} ) ;
129
127
swallowExceptions ( ( ) => this . pythonKernelLauncher ?. dispose ( ) ) ;
130
- swallowExceptions ( ( ) => this . connectionFile ?. dispose ( ) ) ;
131
128
}
132
129
133
130
// Make sure that the heartbeat channel is open for connections
@@ -144,21 +141,42 @@ export class KernelProcess implements IKernelProcess {
144
141
}
145
142
}
146
143
147
- private async createAndUpdateConnectionFile ( ) {
148
- // Create the connection file so that any user can destroy it. The kernel will
149
- // actually read it, delete it, and recreate it with more restricted permissions
150
- this . connectionFile = await this . file . createTemporaryFile ( '.json' , 0o777 ) ;
151
- await this . file . writeFile ( this . connectionFile . filePath , JSON . stringify ( this . _connection ) , {
152
- encoding : 'utf-8' ,
153
- flag : 'w'
154
- } ) ;
155
-
156
- // Update the args in the kernelspec to include the conenction file.
144
+ // Instead of having to use a connection file update our local copy of the kernelspec to launch
145
+ // directly with command line arguments
146
+ private updateConnectionArgs ( ) {
147
+ // First check to see if we have a kernelspec that expects a connection file,
148
+ // Error if we don't have one. We expect '-f', '{connectionfile}' in our launch args
157
149
const indexOfConnectionFile = findIndexOfConnectionFile ( this . _kernelSpec ) ;
158
- if ( indexOfConnectionFile === - 1 ) {
150
+ if (
151
+ indexOfConnectionFile === - 1 ||
152
+ indexOfConnectionFile === 0 ||
153
+ this . _kernelSpec . argv [ indexOfConnectionFile - 1 ] !== '-f'
154
+ ) {
159
155
throw new Error ( `Connection file not found in kernelspec json args, ${ this . _kernelSpec . argv . join ( ' ' ) } ` ) ;
160
156
}
161
- this . _kernelSpec . argv [ indexOfConnectionFile ] = this . connectionFile . filePath ;
157
+
158
+ // Slice out -f and the connection file from the args
159
+ this . _kernelSpec . argv . splice ( indexOfConnectionFile - 1 , 2 ) ;
160
+
161
+ // Add in our connection command line args
162
+ this . _kernelSpec . argv . push ( ...this . addConnectionArgs ( ) ) ;
163
+ }
164
+
165
+ // Add the command line arguments
166
+ private addConnectionArgs ( ) : string [ ] {
167
+ const newConnectionArgs : string [ ] = [ ] ;
168
+
169
+ newConnectionArgs . push ( `--ip=${ this . _connection . ip } ` ) ;
170
+ newConnectionArgs . push ( `--stdin=${ this . _connection . stdin_port } ` ) ;
171
+ newConnectionArgs . push ( `--control=${ this . _connection . control_port } ` ) ;
172
+ newConnectionArgs . push ( `--hb=${ this . _connection . hb_port } ` ) ;
173
+ newConnectionArgs . push ( `--Session.signature_scheme="${ this . _connection . signature_scheme } "` ) ;
174
+ newConnectionArgs . push ( `--Session.key=b"${ this . _connection . key } "` ) ; // Note we need the 'b here at the start for a byte string
175
+ newConnectionArgs . push ( `--shell=${ this . _connection . shell_port } ` ) ;
176
+ newConnectionArgs . push ( `--transport="${ this . _connection . transport } "` ) ;
177
+ newConnectionArgs . push ( `--iopub=${ this . _connection . iopub_port } ` ) ;
178
+
179
+ return newConnectionArgs ;
162
180
}
163
181
164
182
private async launchAsObservable ( ) {
0 commit comments