Skip to content

use only resource on kernel launcher #11339

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

Merged
merged 3 commits into from
Apr 22, 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
16 changes: 4 additions & 12 deletions src/client/datascience/kernel-launcher/kernelFinder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
import { Kernel } from '@jupyterlab/services';
import { inject, injectable, named } from 'inversify';
import * as path from 'path';
import { InterpreterUri } from '../../common/installer/types';
import { traceError, traceInfo } from '../../common/logger';
import { IFileSystem, IPlatformService } from '../../common/platform/types';
import { IExtensionContext, IPathUtils, Resource } from '../../common/types';
import { isResource } from '../../common/utils/misc';
import {
IInterpreterLocatorService,
IInterpreterService,
Expand Down Expand Up @@ -54,11 +52,9 @@ export class KernelFinder implements IKernelFinder {
@inject(IExtensionContext) private readonly context: IExtensionContext
) {}

public async findKernelSpec(interpreterUri: InterpreterUri, kernelName?: string): Promise<IJupyterKernelSpec> {
public async findKernelSpec(resource: Resource, kernelName?: string): Promise<IJupyterKernelSpec> {
this.cache = await this.readCache();
let foundKernel: IJupyterKernelSpec | undefined;
const resource = isResource(interpreterUri) ? interpreterUri : undefined;
const notebookInterpreter = isResource(interpreterUri) ? undefined : interpreterUri;

if (kernelName) {
let kernelSpec = this.cache.find((ks) => ks.name === kernelName);
Expand All @@ -67,13 +63,10 @@ export class KernelFinder implements IKernelFinder {
return kernelSpec;
}

if (!notebookInterpreter) {
kernelSpec = await this.getKernelSpecFromActiveInterpreter(resource, kernelName);
}
kernelSpec = await this.getKernelSpecFromActiveInterpreter(resource, kernelName);

if (kernelSpec) {
// tslint:disable-next-line: no-floating-promises
this.writeCache(this.cache);
this.writeCache(this.cache).ignoreErrors();
Copy link
Member

Choose a reason for hiding this comment

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

👍

return kernelSpec;
}

Expand All @@ -94,8 +87,7 @@ export class KernelFinder implements IKernelFinder {
foundKernel = await this.getDefaultKernelSpec(resource);
}

// tslint:disable-next-line: no-floating-promises
this.writeCache(this.cache);
this.writeCache(this.cache).ignoreErrors();
return foundKernel;
}

Expand Down
9 changes: 3 additions & 6 deletions src/client/datascience/kernel-launcher/kernelLauncher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import * as portfinder from 'portfinder';
import { promisify } from 'util';
import * as uuid from 'uuid/v4';
import { Event, EventEmitter } from 'vscode';
import { InterpreterUri } from '../../common/installer/types';
import { traceInfo, traceWarning } from '../../common/logger';
import { IFileSystem, TemporaryFile } from '../../common/platform/types';
import { IPythonExecutionFactory } from '../../common/process/types';
import { Resource } from '../../common/types';
import { createDeferred, Deferred } from '../../common/utils/async';
import * as localize from '../../common/utils/localize';
import { noop } from '../../common/utils/misc';
Expand Down Expand Up @@ -136,14 +136,11 @@ export class KernelLauncher implements IKernelLauncher {
@inject(IFileSystem) private file: IFileSystem
) {}

public async launch(
interpreterUri: InterpreterUri,
kernelName?: string | IJupyterKernelSpec
): Promise<IKernelProcess> {
public async launch(resource: Resource, kernelName?: string | IJupyterKernelSpec): Promise<IKernelProcess> {
let kernelSpec: IJupyterKernelSpec;
if (!kernelName || typeof kernelName === 'string') {
// string or undefined
kernelSpec = await this.kernelFinder.findKernelSpec(interpreterUri, kernelName);
kernelSpec = await this.kernelFinder.findKernelSpec(resource, kernelName);
} else {
// IJupyterKernelSpec
kernelSpec = kernelName;
Expand Down
28 changes: 1 addition & 27 deletions src/test/datascience/kernelLauncher.functional.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,32 +69,6 @@ suite('DataScience - Kernel Launcher', () => {
}
}).timeout(10_000);

test('Launch from PythonInterpreter', async function () {
if (!process.env.VSCODE_PYTHON_ROLLING) {
// tslint:disable-next-line: no-invalid-this
this.skip();
} else {
const kernel = await kernelLauncher.launch(pythonInterpreter, kernelName);
const exited = new Promise<boolean>((resolve) => kernel.exited(() => resolve(true)));

// It should not exit.
assert.isRejected(
waitForCondition(() => exited, 5_000, 'Timeout'),
'Timeout'
);

assert.isOk<IKernelConnection | undefined>(kernel.connection, 'Connection not found');

// Upon disposing, we should get an exit event within 100ms or less.
// If this happens, then we know a process existed.
kernel.dispose();
assert.isRejected(
waitForCondition(() => exited, 100, 'Timeout'),
'Timeout'
);
}
});

function createExecutionMessage(code: string, sessionId: string): KernelMessage.IExecuteRequestMsg {
return {
channel: 'shell',
Expand Down Expand Up @@ -182,7 +156,7 @@ suite('DataScience - Kernel Launcher', () => {
};
kernelFinder.addKernelSpec(pythonInterpreter.path, spec);

const kernel = await kernelLauncher.launch(pythonInterpreter, kernelName);
const kernel = await kernelLauncher.launch(resource, kernelName);
const exited = new Promise<boolean>((resolve) => kernel.exited(() => resolve(true)));

// It should not exit.
Expand Down