Skip to content

Add ability to reconnect to Jupyter kernel#7015

Closed
kdkavanagh wants to merge 7 commits into
microsoft:masterfrom
kdkavanagh:master
Closed

Add ability to reconnect to Jupyter kernel#7015
kdkavanagh wants to merge 7 commits into
microsoft:masterfrom
kdkavanagh:master

Conversation

@kdkavanagh
Copy link
Copy Markdown

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

  • [X ] Pull request represents a single change (i.e. not fixing disparate/unrelated things in a single PR)
  • [X ] Title summarizes what is changing
  • [X ] Has a news entry file (remember to thank yourself!)
  • [X ] Appropriate comments and documentation strings in the code
  • [X ] Has sufficient logging.
  • [X ] Has telemetry for enhancements.
  • Unit tests & system/integration tests are added/updated
  • [ X] Test plan is updated as appropriate
  • [ X] package-lock.json has been regenerated by running npm install (if dependencies have changed)
  • The wiki is updated with any design decisions/details.

@msftclas
Copy link
Copy Markdown

msftclas commented Aug 18, 2019

CLA assistant check
All CLA requirements met.

@janosh
Copy link
Copy Markdown

janosh commented Aug 19, 2019

Awesome suggestion and great work! Just starting to use remote kernels in VSCode myself and this would be really helpful.

@gramster gramster added data science feature-request Request for new features or functionality labels Aug 20, 2019
@gramster
Copy link
Copy Markdown
Member

This is great, thank you! We will review it ASAP.

@IanMatthewHuff IanMatthewHuff self-requested a review August 20, 2019 23:21
@IanMatthewHuff
Copy link
Copy Markdown
Member

@kdkavanagh . Sorry about the delay here. I've added myself on as a reviewer for this and will take a look first thing tomorrow.

@kdkavanagh
Copy link
Copy Markdown
Author

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

@IanMatthewHuff
Copy link
Copy Markdown
Member

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.

Comment thread package.json
"python.dataScience.jupyterServerKernelId": {
"type": "string",
"default": "",
"description": "Select the Jupyter server Kernel UUID to connect to. Leave blank to start a new kernel",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The kernel here in this string should be lower case.

Comment thread package.json
"python.dataScience.jupyterServerAllowKernelShutdown": {
"type": "boolean",
"default": true,
"description": "Shutdown the Jupyter kernel when finished",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"." at the end of this string to make it a full sentence.

Comment thread package.nls.json
"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",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lower case kernel in a couple of instances here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@hochshi
Copy link
Copy Markdown

hochshi commented Sep 3, 2019

Hi,
I've applied the requested changes with some extras.
Mainly, the user can now specify which kernel to start instead of using the base kernel every time.

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> {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sessionChanged [](start = 15, length = 14)

I believe the linter will complain here. This should be where it was before.

Copy link
Copy Markdown

@rchiodo rchiodo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🕐

// 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;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@rchiodo
Copy link
Copy Markdown

rchiodo commented Oct 10, 2019

Since @hochshi has taken this over, closing this PR

@rchiodo rchiodo closed this Oct 10, 2019
@lock lock Bot locked as resolved and limited conversation to collaborators Oct 17, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

feature-request Request for new features or functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants