-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Fixes to blowing away of kernel info & not using right startup info #14295
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -122,7 +122,12 @@ export abstract class BaseJupyterSession implements IJupyterSession { | |||
); | |||
} | |||
} | |||
|
|||
public async requestKernelInfo(): Promise<KernelMessage.IInfoReplyMsg> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the information stored in the metatadata of the notebook.
Today we're handcrafting this, we can instead get this from the kernel.
@@ -124,8 +127,9 @@ export class Kernel implements IKernel { | |||
} else { | |||
await this.validate(this.uri); | |||
const metadata = ((getDefaultNotebookContent().metadata || {}) as unknown) as nbformat.INotebookMetadata; | |||
// Create a dummy notebook metadata & update the metadata before starting the notebook (required to ensure we fetch & start the right kernel). | |||
// Lower layers of code below getOrCreateNotebook searches for kernels again using the metadata. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the code that's not right.
I've created an issue for this (possibly closed).
Basically we're doing all of the searching for kernels & finding the kernel information, etc..
However, when starting a notebook, we have to pass the notebook metadata as that is what's used by NotebookProvider.getOrCreateNotebook
to start the real notebook/kernel.
However this is based on the notebook metadata, & we're not passing that in here, instead we pass the kernel connection metatadata. & the work around here is to generate a dummy object that looks like a notebook metadata & hydrate that with information from the kernel connection.
I still don't like this,
Basically we do all of the search, translate to kernelConnection & then we build another object from that & lower down we search for the right kernel using the information in what's supposed to be the metadata in the ipynb file.
@@ -142,15 +141,7 @@ export class KernelExecution implements IDisposable { | |||
await this.validateKernel(document); | |||
let kernel = this.kernelProvider.get(document.uri); | |||
if (!kernel) { | |||
const activeInterpreter = await this.interpreterService.getActiveInterpreter(document.uri); | |||
kernel = this.kernelProvider.getOrCreate(document.uri, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was wrong, we were hand crafting the kernel connection metadata instead of using the one provided.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basically starting a kernel from a kernel spec would never have worked with the old code (for native notebooks).
data.metadata = kernelConnection; | ||
kernelInformationForNotebooks.set(document, data); | ||
} | ||
export function updateKernelInfoInNotebookMetadata( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We keep track of the kernel information, just as we keep track of the notebook metadata & update it only when writing to disc.
Using same (existing) technique.
I.e. the contents (metadata) get computed only at the time data is written to disc
} | ||
public cancelCellExecution(_: NotebookDocument, cell: NotebookCell) { | ||
this.kernelProvider.get(cell.notebook.uri)?.interrupt(); // NOSONAR | ||
} | ||
public cancelAllCellsExecution(document: NotebookDocument) { | ||
this.kernelProvider.get(document.uri)?.interrupt(); // NOSONAR | ||
} | ||
private updateKernelInfoInNotebookWhenAvailable(kernel: IKernel, doc: NotebookDocument) { | ||
const disposable = kernel.onStatusChanged(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kernel information is only available after the kernel has been started.
Unfortunately the kernel does not have a link back to the notebook, hence we need to monitor the status here & update the metadata accordingly.
metadata.language_info = undefined; | ||
changed = true; | ||
if (kernelInfo && kernelInfo.status === 'ok') { | ||
if (!fastDeepEqual(metadata.language_info, kernelInfo.language_info)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we have kernel info, use that.
Else do not blow away existing data, blow it away only for python
(backwards compatible).
Personally I think we should never hand craft it, as we can get all of this from the kernel (do what Jupyter does always).
file: uri, | ||
possibleContents, | ||
skipLoadingDirtyContents: true, | ||
isNative: forVSCodeNotebooks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed a bug.
Codecov Report
@@ Coverage Diff @@
## main #14295 +/- ##
==========================================
+ Coverage 59.75% 59.85% +0.10%
==========================================
Files 697 709 +12
Lines 38649 39362 +713
Branches 5577 5705 +128
==========================================
+ Hits 23094 23562 +468
- Misses 14364 14558 +194
- Partials 1191 1242 +51
Continue to review full report at Codecov.
|
Kudos, SonarCloud Quality Gate passed!
|
Here's what the metadata in ipynb looks like: