Skip to content
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

Add interrupt_mode & getSpec #3951

Merged
merged 4 commits into from
Nov 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/client/datascience/jupyter/kernels/jupyterKernelSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export class JupyterKernelSpec implements IJupyterKernelSpec {
public readonly env: NodeJS.ProcessEnv | undefined;
public display_name: string;
public argv: string[];
public interrupt_mode?: 'message' | 'signal';

// tslint:disable-next-line: no-any
public metadata?: Record<string, any> & { interpreter?: Partial<PythonEnvironment> };
Expand All @@ -36,6 +37,8 @@ export class JupyterKernelSpec implements IJupyterKernelSpec {
this.metadata = specModel.metadata;
// tslint:disable-next-line: no-any
this.env = specModel.env as any; // JSONObject, but should match
// tslint:disable-next-line: no-any
this.interrupt_mode = specModel.interrupt_mode as any;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is part of the spec. If interrupt_mode = 'message' we should send a message to the kernel to interrupt. Rust is one such kernel.
Not fixing this, just exposing this information so we can use it when fixing other realted issues

}
}

Expand Down
17 changes: 14 additions & 3 deletions src/client/datascience/raw-kernel/rawKernel.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import type { Kernel, KernelMessage, ServerConnection } from '@jupyterlab/services';
import { Kernel, KernelMessage, ServerConnection } from '@jupyterlab/services';
// tslint:disable: no-any no-require-imports
import cloneDeep = require('lodash/cloneDeep');
import * as uuid from 'uuid/v4';
import { isTestExecution } from '../../common/constants';
import { traceError } from '../../common/logger';
import { IDisposable } from '../../common/types';
import { swallowExceptions } from '../../common/utils/misc';
import { getNameOfKernelConnection } from '../jupyter/kernels/helpers';
import { IKernelProcess } from '../kernel-launcher/types';
import { IWebSocketLike } from '../kernelSocketWrapper';
import { IKernelSocket } from '../types';
import { RawSocket } from './rawSocket';
// tslint:disable: no-any no-require-imports

export function suppressShutdownErrors(realKernel: any) {
// When running under a test, mark all futures as done so we
Expand Down Expand Up @@ -111,7 +113,16 @@ export class RawKernel implements Kernel.IKernel {
await this.kernelProcess.dispose();
this.socket.dispose();
}
public getSpec(): Promise<Kernel.ISpecModel> {
public async getSpec(): Promise<Kernel.ISpecModel> {
if (this.kernelProcess.kernelConnectionMetadata.kind === 'startUsingKernelSpec') {
const kernelSpec = cloneDeep(this.kernelProcess.kernelConnectionMetadata.kernelSpec) as any;
const resources = 'resources' in kernelSpec ? kernelSpec.resources : {};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

When using raw kernels, we have the kernel spec, hence return that.
Not used today, but will be used in long running kernels, noop change.

return {
...kernelSpec,
resources
};
}
traceError('Fetching kernel spec from raw kernel using JLab API');
return this.realKernel.getSpec();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This API doesn't work, realKernel.getSpec goes to Jupyter Lab API and that attempts to make a REST call to the base (dummy url).
This should not get executed hence added error logging.

}
public sendShellMessage<T extends KernelMessage.ShellMessageType>(
Expand Down
1 change: 1 addition & 0 deletions src/client/datascience/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ export interface IJupyterKernelSpec {
* Plenty of conda packages ship kernels in this manner (beakerx, etc).
*/
interpreterPath?: string;
readonly interrupt_mode?: 'message' | 'signal';
}

export const INotebookImporter = Symbol('INotebookImporter');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,8 @@ suite('Kernel Finder', () => {
});
// Ignore some properties when comparing.
assert.deepEqual(
{ ...spec, specFile: '', interpreterPath: '' },
{ ...kernel, specFile: '', interpreterPath: '' },
{ ...spec, specFile: '', interpreterPath: '', interrupt_mode: 'message' },
{ ...kernel, specFile: '', interpreterPath: '', interrupt_mode: 'message' },
'The found kernel spec is not the same.'
);
fileSystem.reset();
Expand Down