From 6c5d35eaae9f43d5589bc9d9a677b185416ded49 Mon Sep 17 00:00:00 2001 From: Lucy Zhang Date: Fri, 9 Jul 2021 12:51:21 -0700 Subject: [PATCH] Check kernel dependencies when a new session is started (#16040) * check dependencies when a new session is started * fix test * fix issue when kernel spec is not found --- .../notebook/src/jupyter/jupyterServerInstallation.ts | 2 +- extensions/notebook/src/jupyter/jupyterSessionManager.ts | 6 ++++++ extensions/notebook/src/test/model/sessionManager.test.ts | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/extensions/notebook/src/jupyter/jupyterServerInstallation.ts b/extensions/notebook/src/jupyter/jupyterServerInstallation.ts index 0410599e3b..94c4b4460c 100644 --- a/extensions/notebook/src/jupyter/jupyterServerInstallation.ts +++ b/extensions/notebook/src/jupyter/jupyterServerInstallation.ts @@ -476,7 +476,7 @@ export class JupyterServerInstallation implements IJupyterServerInstallation { await fs.remove(this._oldPythonInstallationPath); this._upgradeInProcess = false; - } else { + } else if (!installSettings.packageUpgradeOnly) { await vscode.commands.executeCommand('notebook.action.restartJupyterNotebookSessions'); } }) diff --git a/extensions/notebook/src/jupyter/jupyterSessionManager.ts b/extensions/notebook/src/jupyter/jupyterSessionManager.ts index 9be5de2a50..1ea09d2be8 100644 --- a/extensions/notebook/src/jupyter/jupyterSessionManager.ts +++ b/extensions/notebook/src/jupyter/jupyterSessionManager.ts @@ -129,6 +129,12 @@ export class JupyterSessionManager implements nb.SessionManager { // no-op return Promise.reject(new Error(localize('errorStartBeforeReady', "Cannot start a session, the manager is not yet initialized"))); } + + // Prompt for Python Install to check that all dependencies are installed. + // This prevents the kernel from getting stuck if a user deletes a dependency after the server has been started. + let kernelDisplayName: string = this.specs?.kernels.find(k => k.name === options.kernelName)?.display_name; + await this._installation?.promptForPythonInstall(kernelDisplayName); + let sessionImpl = await this._sessionManager.startNew(options); let jupyterSession = new JupyterSession(sessionImpl, this._installation, skipSettingEnvironmentVars, this._installation?.pythonEnvVarPath); await jupyterSession.messagesComplete; diff --git a/extensions/notebook/src/test/model/sessionManager.test.ts b/extensions/notebook/src/test/model/sessionManager.test.ts index 01582cdd26..0310b669d4 100644 --- a/extensions/notebook/src/test/model/sessionManager.test.ts +++ b/extensions/notebook/src/test/model/sessionManager.test.ts @@ -115,6 +115,7 @@ describe('Jupyter Session Manager', function (): void { } }; mockJupyterManager.setup(m => m.startNew(TypeMoq.It.isAny())).returns(() => Promise.resolve(expectedSessionInfo)); + mockJupyterManager.setup(m => m.specs).returns(() => undefined); // When I call startSession let session = await sessionManager.startNew(sessionOptions, true);