@@ -10,6 +10,7 @@ import { IDisposable, IOutputChannel, Resource } from '../../common/types';
1010import { waitForPromise } from '../../common/utils/async' ;
1111import * as localize from '../../common/utils/localize' ;
1212import { noop } from '../../common/utils/misc' ;
13+ import { PythonInterpreter } from '../../interpreter/contracts' ;
1314import { captureTelemetry , sendTelemetryEvent } from '../../telemetry' ;
1415import { BaseJupyterSession } from '../baseJupyterSession' ;
1516import { Identifiers , Telemetry } from '../constants' ;
@@ -62,6 +63,7 @@ export class RawJupyterSession extends BaseJupyterSession {
6263 public async connect (
6364 kernelSpec : IJupyterKernelSpec ,
6465 timeout : number ,
66+ interpreter ?: PythonInterpreter ,
6567 cancelToken ?: CancellationToken
6668 ) : Promise < IJupyterKernelSpec | undefined > {
6769 // Save the resource that we connect with
@@ -71,7 +73,7 @@ export class RawJupyterSession extends BaseJupyterSession {
7173 // Notebook Provider level will handle the thrown error
7274 newSession = await waitForPromise (
7375 Promise . race ( [
74- this . startRawSession ( kernelSpec , cancelToken ) ,
76+ this . startRawSession ( kernelSpec , interpreter , cancelToken ) ,
7577 createPromiseFromCancellation ( {
7678 cancelAction : 'reject' ,
7779 defaultValue : new CancellationError ( ) ,
@@ -94,7 +96,11 @@ export class RawJupyterSession extends BaseJupyterSession {
9496 sendTelemetryEvent ( Telemetry . RawKernelSessionStartSuccess ) ;
9597 traceInfo ( 'Raw session started and connected' ) ;
9698 this . setSession ( newSession ) ;
99+
100+ // Update kernelspec and interpreter
97101 this . kernelSpec = newSession . kernelProcess ?. kernelSpec ;
102+ this . interpreter = interpreter ;
103+
98104 this . outputChannel . appendLine (
99105 localize . DataScience . kernelStarted ( ) . format ( this . kernelSpec . display_name || this . kernelSpec . name )
100106 ) ;
@@ -115,7 +121,8 @@ export class RawJupyterSession extends BaseJupyterSession {
115121
116122 public async createNewKernelSession (
117123 kernel : IJupyterKernelSpec | LiveKernelModel ,
118- _timeoutMS : number
124+ _timeoutMS : number ,
125+ interpreter ?: PythonInterpreter
119126 ) : Promise < ISessionWithSocket > {
120127 if ( ! kernel || 'session' in kernel ) {
121128 // Don't allow for connecting to a LiveKernelModel
@@ -124,7 +131,7 @@ export class RawJupyterSession extends BaseJupyterSession {
124131
125132 this . outputChannel . appendLine ( localize . DataScience . kernelStarted ( ) . format ( kernel . display_name || kernel . name ) ) ;
126133
127- return this . startRawSession ( kernel ) ;
134+ return this . startRawSession ( kernel , interpreter ) ;
128135 }
129136
130137 protected shutdownSession (
@@ -161,19 +168,20 @@ export class RawJupyterSession extends BaseJupyterSession {
161168
162169 protected startRestartSession ( ) {
163170 if ( ! this . restartSessionPromise && this . session ) {
164- this . restartSessionPromise = this . createRestartSession ( this . kernelSpec , this . session ) ;
171+ this . restartSessionPromise = this . createRestartSession ( this . kernelSpec , this . session , this . interpreter ) ;
165172 }
166173 }
167174 protected async createRestartSession (
168175 kernelSpec : IJupyterKernelSpec | LiveKernelModel | undefined ,
169176 _session : ISessionWithSocket ,
177+ interpreter ?: PythonInterpreter ,
170178 cancelToken ?: CancellationToken
171179 ) : Promise < ISessionWithSocket > {
172180 if ( ! kernelSpec || 'session' in kernelSpec ) {
173181 // Need to have connected before restarting and can't use a LiveKernelModel
174182 throw new Error ( localize . DataScience . sessionDisposed ( ) ) ;
175183 }
176- const startPromise = this . startRawSession ( kernelSpec , cancelToken ) ;
184+ const startPromise = this . startRawSession ( kernelSpec , interpreter , cancelToken ) ;
177185 return startPromise . then ( ( session ) => {
178186 this . kernelSelector . addKernelToIgnoreList ( session . kernel ) ;
179187 return session ;
@@ -183,6 +191,7 @@ export class RawJupyterSession extends BaseJupyterSession {
183191 @captureTelemetry ( Telemetry . RawKernelStartRawSession , undefined , true )
184192 private async startRawSession (
185193 kernelSpec : IJupyterKernelSpec ,
194+ interpreter ?: PythonInterpreter ,
186195 cancelToken ?: CancellationToken
187196 ) : Promise < RawSession > {
188197 const cancellationPromise = createPromiseFromCancellation ( {
@@ -193,7 +202,7 @@ export class RawJupyterSession extends BaseJupyterSession {
193202 cancellationPromise . catch ( noop ) ;
194203
195204 const process = await Promise . race ( [
196- this . kernelLauncher . launch ( kernelSpec , this . resource ) ,
205+ this . kernelLauncher . launch ( kernelSpec , this . resource , interpreter ) ,
197206 cancellationPromise
198207 ] ) ;
199208
0 commit comments