Add ability to reconnect to Jupyter kernel#7015
Conversation
|
Awesome suggestion and great work! Just starting to use remote kernels in VSCode myself and this would be really helpful. |
|
This is great, thank you! We will review it ASAP. |
|
@kdkavanagh . Sorry about the delay here. I've added myself on as a reviewer for this and will take a look first thing tomorrow. |
|
One thing to note - If you choose to start your own kernel, VSCode ends up creating two sessions/kernels when you initially load the interactive window. I saw the code for this, but failed to grasp the reasoning behind it, so left it alone. This can be somewhat confusing when you come back to reconnect to the server and see two kernels when you wouldve only expected one |
The second session is used for the restart kernel command. We essentially always have a backup session running, and when user asks for a restart we just swap in the backup. Was a pretty big speed up for the restart operation. |
| "python.dataScience.jupyterServerKernelId": { | ||
| "type": "string", | ||
| "default": "", | ||
| "description": "Select the Jupyter server Kernel UUID to connect to. Leave blank to start a new kernel", |
There was a problem hiding this comment.
The kernel here in this string should be lower case.
| "python.dataScience.jupyterServerAllowKernelShutdown": { | ||
| "type": "boolean", | ||
| "default": true, | ||
| "description": "Shutdown the Jupyter kernel when finished", |
There was a problem hiding this comment.
"." at the end of this string to make it a full sentence.
| "DataScience.jupyterSelectURISpecifyURI": "Type in the URI to connect to a running Jupyter server", | ||
| "DataScience.jupyterSelectURIPrompt": "Enter the URI of a Jupyter server", | ||
| "DataScience.jupyterSelectURIInvalidURI": "Invalid URI specified", | ||
| "DataScience.jupyterServerReconnectKernelLocal": "Select Jupyer Kernel", |
There was a problem hiding this comment.
Lower case kernel in a couple of instances here.
There was a problem hiding this comment.
Also the Local on the end isn't needed. We don't use that for our localized strings and it could cause some confusion with actual Local / Remote server cases.
| import { JupyterExecutionBase } from './jupyter/jupyterExecution'; | ||
| import { ICodeWatcher, IDataScience, IDataScienceCodeLensProvider, IDataScienceCommandListener, IJupyterSessionManager } from './types'; | ||
|
|
||
| interface IKernelQuickPickItem extends vscode.QuickPickItem { |
There was a problem hiding this comment.
If you could bump this over into the ./types file that is where we keep our vscode extension types.
| allowShutdown = false; | ||
| } | ||
| sendTelemetryEvent(Telemetry.JupyterKernelAutoShutdown, undefined, { autoShutdownEnabled: allowShutdown }); | ||
| await this.configuration.updateSetting('dataScience.jupyterServerAllowKernelShutdown', allowShutdown, undefined, vscode.ConfigurationTarget.Workspace); |
There was a problem hiding this comment.
This looks solid, with one small change needed here. Currently these settings are specified when selecting a remote server URI, but they also are applying for the local launch case. Given that the ID / Shutdown are specified after the remote URI I think that users would be surprised if they move back to working locally and all of a sudden their session are not shutting down on close. These setting should be cleared out in the SetJupyterURIToLocal case.
| // Create a new session and attempt to connect to it | ||
| const session = new JupyterSession(connInfo, kernelSpec, this.jupyterPasswordConnect); | ||
| const settings = this.configurationService.getSettings(); | ||
| const allowShutdown = settings.datascience.jupyterServerAllowKernelShutdown; |
There was a problem hiding this comment.
These settings will need to be passed down here via the IConnection object and via the INotebookServerOptions at the JupyterExecution startOrConnect level not pulled directly from the configuration. We use those INotebookServerOption to determine if we can resuse an existing connection in serverCache.ts. With this implemented as is our code will see a connection to server A kernel B as the exact same as a connection to server A kernel C and will try to reuse the old connection, even if the user has specified a new kernel to connect to.
|
Hi, One thing to note, when leaving the kernel running, it is not clear how should the user kill that kernel - perhaps a kill button should be added to the interactive python window. How would you like me to proceed? Create a new PR? |
|
|
||
| export class JupyterExecutionBase implements IJupyterExecution { | ||
|
|
||
| public get sessionChanged(): Event<void> { |
There was a problem hiding this comment.
sessionChanged [](start = 15, length = 14)
I believe the linter will complain here. This should be where it was before.
| // Create a new session and attempt to connect to it | ||
| const session = new JupyterSession(connInfo, kernelSpec, this.jupyterPasswordConnect); | ||
| const settings = this.configurationService.getSettings(); | ||
| const allowShutdown = settings.datascience.jupyterServerAllowKernelShutdown; |
There was a problem hiding this comment.
jupyterServerAllowKernelShutdown [](start = 51, length = 32)
Related to what Ian said in datascience.ts, I think the allowKernelShutdown should only be used if were in a remote situation. You could check that here by looking at the localLaunch field of the connInfo
|
Since @hochshi has taken this over, closing this PR |
For #7014
Adds two new user-facing parameters presented after entering a remote jupyter URI which allow the user to reconnect to a kernel already running on the server and the option to leave that kernel running when the interactive window is closed
Test plan is updated as appropriatepackage-lock.jsonhas been regenerated by runningnpm install(if dependencies have changed)