From ff1a64215774d1d2cfda442f21f101c31226b09e Mon Sep 17 00:00:00 2001 From: Lucy Zhang Date: Fri, 25 Jun 2021 18:16:32 -0400 Subject: [PATCH] Add jupyter server shutdown timeout setting (#15913) * add jupyter server shutdown timeout setting * no timeout if setting is 0 * set minimum value to 0 --- extensions/notebook/package.json | 6 ++++++ extensions/notebook/package.nls.json | 1 + extensions/notebook/src/common/constants.ts | 1 + .../src/jupyter/jupyterNotebookProvider.ts | 18 +++++++++++------- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/extensions/notebook/package.json b/extensions/notebook/package.json index 012484cdd6..d6a103bbc9 100644 --- a/extensions/notebook/package.json +++ b/extensions/notebook/package.json @@ -43,6 +43,12 @@ "default": false, "description": "%notebook.dontPromptPythonUpdate.description%" }, + "notebook.jupyterServerShutdownTimeout": { + "type": "number", + "default": 5, + "minimum": 0, + "description": "%notebook.jupyterServerShutdownTimeout.description%" + }, "notebook.overrideEditorTheming": { "type": "boolean", "default": true, diff --git a/extensions/notebook/package.nls.json b/extensions/notebook/package.nls.json index 0569968594..d0f2feb595 100644 --- a/extensions/notebook/package.nls.json +++ b/extensions/notebook/package.nls.json @@ -5,6 +5,7 @@ "notebook.pythonPath.description": "Local path to python installation used by Notebooks.", "notebook.useExistingPython.description": "Local path to a preexisting python installation used by Notebooks.", "notebook.dontPromptPythonUpdate.description": "Do not show prompt to update Python.", + "notebook.jupyterServerShutdownTimeout.description": "The amount of time (in minutes) to wait before shutting down a server after all notebooks are closed. (Enter 0 to not shutdown)", "notebook.overrideEditorTheming.description": "Override editor default settings in the Notebook editor. Settings include background color, current line color and border", "notebook.maxTableRows.description": "Maximum number of rows returned per table in the Notebook editor", "notebook.trustedBooks.description": "Notebooks contained in these books will automatically be trusted.", diff --git a/extensions/notebook/src/common/constants.ts b/extensions/notebook/src/common/constants.ts index c7a8bbbd58..12ae561cc2 100644 --- a/extensions/notebook/src/common/constants.ts +++ b/extensions/notebook/src/common/constants.ts @@ -17,6 +17,7 @@ export const pythonVersion = '3.8.10'; export const pythonPathConfigKey = 'pythonPath'; export const existingPythonConfigKey = 'useExistingPython'; export const dontPromptPythonUpdate = 'dontPromptPythonUpdate'; +export const jupyterServerShutdownTimeoutConfigKey = 'jupyterServerShutdownTimeout'; export const notebookConfigKey = 'notebook'; export const trustedBooksConfigKey = 'trustedBooks'; export const pinnedBooksConfigKey = 'pinnedNotebooks'; diff --git a/extensions/notebook/src/jupyter/jupyterNotebookProvider.ts b/extensions/notebook/src/jupyter/jupyterNotebookProvider.ts index e92a9dca5e..b4b65038cb 100644 --- a/extensions/notebook/src/jupyter/jupyterNotebookProvider.ts +++ b/extensions/notebook/src/jupyter/jupyterNotebookProvider.ts @@ -64,13 +64,17 @@ export class JupyterNotebookProvider implements nb.NotebookProvider { manager.sessionManager.shutdown(session.id); } if (sessionManager.listRunning().length === 0) { - const TenMinutesInMs = 10 * 60 * 1000; - setTimeout(() => { - if (sessionManager.listRunning().length === 0) { - this.managerTracker.delete(baseFolder); - manager.dispose(); - } - }, TenMinutesInMs); + let notebookConfig: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration(constants.notebookConfigKey); + let timeoutInMinutes: number = notebookConfig.get(constants.jupyterServerShutdownTimeoutConfigKey); + if (timeoutInMinutes > 0) { + const timeoutInMs = timeoutInMinutes * 60 * 1000; + setTimeout(() => { + if (sessionManager.listRunning().length === 0) { + this.managerTracker.delete(baseFolder); + manager.dispose(); + } + }, timeoutInMs); + } } } }