Skip to content

Commit

Permalink
Merge pull request #6246 from jasongrout/autorestart
Browse files Browse the repository at this point in the history
Notify the user when a notebook kernel autorestarts
  • Loading branch information
blink1073 committed May 15, 2019
2 parents 86176e6 + 8ea8e92 commit dcda928
Show file tree
Hide file tree
Showing 16 changed files with 318 additions and 239 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -26,7 +26,7 @@
"clean:src": "jlpm run clean",
"clean:test": "lerna run clean --scope \"@jupyterlab/test-*\"",
"clean:utils": "cd buildutils && jlpm run clean",
"coverage": "lerna run coverage --scope \"@jupyterlab/test-*\" --stream --concurrency 1",
"coverage": "lerna run coverage --scope \"@jupyterlab/test-*\" --stream --concurrency 1 --no-bail",
"create:package": "node buildutils/lib/create-package.js",
"create:test": "node buildutils/lib/create-test-package.js",
"create:theme": "node buildutils/lib/create-theme.js",
Expand Down
23 changes: 11 additions & 12 deletions packages/apputils/src/clientsession.tsx
Expand Up @@ -878,26 +878,25 @@ export namespace ClientSession {
*
* Returns a promise resolving with whether the kernel was restarted.
*/
export function restartKernel(
export async function restartKernel(
kernel: Kernel.IKernelConnection
): Promise<boolean> {
let restartBtn = Dialog.warnButton({ label: 'RESTART ' });
return showDialog({
const result = await showDialog({
title: 'Restart Kernel?',
body:
'Do you want to restart the current kernel? All variables will be lost.',
buttons: [Dialog.cancelButton(), restartBtn]
}).then(result => {
if (kernel.isDisposed) {
return Promise.resolve(false);
}
if (result.button.accept) {
return kernel.restart().then(() => {
return true;
});
}
return false;
});

if (kernel.isDisposed) {
return false;
}
if (result.button.accept) {
await kernel.restart();
return true;
}
return false;
}

/**
Expand Down
19 changes: 15 additions & 4 deletions packages/apputils/src/toolbar.tsx
Expand Up @@ -3,6 +3,8 @@

import { UseSignal, ReactWidget } from './vdom';

import { Kernel } from '@jupyterlab/services';

import { Button } from '@jupyterlab/ui-components';

import { IIterator, find, map, some } from '@phosphor/algorithm';
Expand Down Expand Up @@ -400,8 +402,7 @@ export namespace Toolbar {
* Create a kernel status indicator item.
*
* #### Notes
* It show display a busy status if the kernel status is
* not idle.
* It will show a busy status if the kernel status is busy.
* It will show the current status in the node title.
* It can handle a change to the context or the kernel.
*/
Expand Down Expand Up @@ -679,10 +680,20 @@ namespace Private {
return;
}
let status = session.status;
this.toggleClass(TOOLBAR_IDLE_CLASS, status === 'idle');
this.toggleClass(TOOLBAR_BUSY_CLASS, status !== 'idle');
const busy = this._isBusy(status);
this.toggleClass(TOOLBAR_BUSY_CLASS, busy);
this.toggleClass(TOOLBAR_IDLE_CLASS, !busy);
let title = 'Kernel ' + status[0].toUpperCase() + status.slice(1);
this.node.title = title;
}

/**
* Check if status should be shown as busy.
*/
private _isBusy(status: Kernel.Status): boolean {
return (
status === 'busy' || status === 'starting' || status === 'restarting'
);
}
}
}
4 changes: 2 additions & 2 deletions packages/console/src/widget.ts
Expand Up @@ -784,8 +784,7 @@ export class CodeConsole extends Widget {
if (!kernel) {
return;
}
kernel
.requestKernelInfo()
kernel.ready
.then(() => {
if (this.isDisposed || !kernel || !kernel.info) {
return;
Expand All @@ -797,6 +796,7 @@ export class CodeConsole extends Widget {
});
} else if (this.session.status === 'restarting') {
this.addBanner();
this._handleInfo(this.session.kernel.info);
}
}

Expand Down
46 changes: 44 additions & 2 deletions packages/notebook/src/panel.ts
Expand Up @@ -9,7 +9,12 @@ import { Message } from '@phosphor/messaging';

import { ISignal, Signal } from '@phosphor/signaling';

import { IClientSession, Printing } from '@jupyterlab/apputils';
import {
IClientSession,
Printing,
showDialog,
Dialog
} from '@jupyterlab/apputils';

import { DocumentWidget } from '@jupyterlab/docregistry';

Expand Down Expand Up @@ -51,6 +56,10 @@ export class NotebookPanel extends DocumentWidget<Notebook, INotebookModel> {
// Set up things related to the context
this.content.model = this.context.model;
this.context.session.kernelChanged.connect(this._onKernelChanged, this);
this.context.session.statusChanged.connect(
this._onSessionStatusChanged,
this
);

void this.revealed.then(() => {
// Set the document edit mode on initial open if it looks like a new document.
Expand Down Expand Up @@ -184,13 +193,40 @@ export class NotebookPanel extends DocumentWidget<Notebook, INotebookModel> {
}
let { newValue } = args;
void newValue.ready.then(() => {
if (this.model) {
if (this.model && this.context.session.kernel === newValue) {
this._updateLanguage(newValue.info.language_info);
}
});
void this._updateSpec(newValue);
}

private _onSessionStatusChanged(
sender: IClientSession,
status: Kernel.Status
) {
// If the status is autorestarting, and we aren't already in a series of
// autorestarts, show the dialog.
if (status === 'autorestarting' && !this._autorestarting) {
// The kernel died and the server is restarting it. We notify the user so
// they know why their kernel state is gone.
void showDialog({
title: 'Kernel Restarting',
body: `The kernel for ${
this.session.path
} appears to have died. It will restart automatically.`,
buttons: [Dialog.okButton()]
});
this._autorestarting = true;
} else if (status === 'restarting') {
// Another autorestart attempt will first change the status to
// restarting, then to autorestarting again, so we don't reset the
// autorestarting status if the status is 'restarting'.
/* no-op */
} else {
this._autorestarting = false;
}
}

/**
* Update the kernel language.
*/
Expand All @@ -215,6 +251,12 @@ export class NotebookPanel extends DocumentWidget<Notebook, INotebookModel> {
}

private _activated = new Signal<this, void>(this);

/**
* Whether we are currently in a series of autorestarts we have already
* notified the user about.
*/
private _autorestarting = false;
}

/**
Expand Down

0 comments on commit dcda928

Please sign in to comment.