Skip to content

Commit

Permalink
Add logging for interrupts (#5722)
Browse files Browse the repository at this point in the history
  • Loading branch information
DonJayamanne authored May 1, 2021
1 parent a50f3ed commit c7d5fde
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import * as path from 'path';
import { NotebookCell, Uri } from 'vscode';

import { ICommandManager } from '../../common/application/types';
import { traceError } from '../../common/logger';
import { traceError, traceInfo } from '../../common/logger';
import { IDisposableRegistry } from '../../common/types';
import { captureTelemetry } from '../../telemetry';
import { CommandSource } from '../../testing/common/constants';
Expand Down Expand Up @@ -102,14 +102,20 @@ export class NativeEditorCommandListener implements IDataScienceCommandListener
private interruptKernel(document: Uri | undefined) {
// `document` may be undefined if this command is invoked from the command palette.
if (document) {
traceInfo(`Interrupt requested for ${document.toString()} in nativeEditorCommandListener`);
const target =
this.provider.activeEditor?.file.toString() === document.toString()
? this.provider.activeEditor
: this.provider.editors.find((editor) => editor.file.toString() === document.toString());
if (target) {
target.interruptKernel().ignoreErrors();
} else {
traceInfo(
`Interrupt requested for ${document.toString()} in nativeEditorCommandListener & editor not found`
);
}
} else {
traceInfo(`Interrupt requested for active editor in nativeEditorCommandListener`);
this.provider.activeEditor?.interruptKernel().ignoreErrors();
}
}
Expand Down
7 changes: 6 additions & 1 deletion src/client/datascience/notebook/notebookEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
WebviewPanel
} from 'vscode';
import { IApplicationShell, ICommandManager, IVSCodeNotebook } from '../../common/application/types';
import { traceError } from '../../common/logger';
import { traceError, traceInfo } from '../../common/logger';
import { IConfigurationService, IDisposable, IDisposableRegistry } from '../../common/types';
import { DataScience } from '../../common/utils/localize';
import { noop } from '../../common/utils/misc';
Expand Down Expand Up @@ -217,17 +217,22 @@ export class NotebookEditor implements INotebookEditor {
}
public async interruptKernel(): Promise<void> {
if (this.restartingKernel) {
traceInfo(`Interrupt requested & currently restarting ${this.document.uri} in notebookEditor.`);
trackKernelResourceInformation(this.document.uri, { interruptKernel: true });
return;
}
const kernel = this.kernelProvider.get(this.file);
if (!kernel || this.restartingKernel) {
traceInfo(
`Interrupt requested & no kernel or currently restarting ${this.document.uri} in notebookEditor.`
);
trackKernelResourceInformation(this.document.uri, { interruptKernel: true });
return;
}
const status = this.statusProvider.set(DataScience.interruptKernelStatus(), true, undefined, undefined);

try {
traceInfo(`Interrupt requested & sent for ${this.document.uri} in notebookEditor.`);
const result = await kernel.interrupt(this.document);
if (result === InterruptResult.TimedOut) {
const message = DataScience.restartKernelAfterInterruptMessage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ suite('DataScience - VSCode Notebook - (Execution) (slow)', function () {
);

// Interrupt the kernel).
traceInfo(`Interrupt requested for ${vscodeNotebook.activeNotebookEditor?.document?.uri} in test`);
await commands.executeCommand(
'jupyter.notebookeditor.interruptkernel',
vscodeNotebook.activeNotebookEditor?.document
Expand Down

0 comments on commit c7d5fde

Please sign in to comment.