Skip to content

Commit

Permalink
Update kernel status to have a connection status and a kernel status.
Browse files Browse the repository at this point in the history
This simplified logic quite a bit.

Most of these ideas came from previous work in #4724
  • Loading branch information
jasongrout committed Sep 21, 2019
1 parent 49fdcfe commit b893d5c
Show file tree
Hide file tree
Showing 7 changed files with 297 additions and 250 deletions.
25 changes: 5 additions & 20 deletions packages/console/src/widget.ts
Expand Up @@ -774,38 +774,23 @@ export class CodeConsole extends Widget {
/**
* Handle a change to the kernel.
*/
private _onKernelChanged(): void {
private async _onKernelChanged(): Promise<void> {
this.clear();
if (this._banner) {
this._banner.dispose();
this._banner = null;
}
this.addBanner();
this._handleInfo(await this.session.kernel.info);
}

/**
* Handle a change to the kernel status.
*/
private _onKernelStatusChanged(): void {
if (this.session.status === 'connected') {
// we just had a kernel restart or reconnect - reset banner
let kernel = this.session.kernel;
if (!kernel) {
return;
}
kernel.ready
.then(() => {
if (this.isDisposed || !kernel || !kernel.info) {
return;
}
this._handleInfo(this.session.kernel.info);
})
.catch(err => {
console.error('could not get kernel info');
});
} else if (this.session.status === 'restarting') {
private async _onKernelStatusChanged(): Promise<void> {
if (this.session.status === 'restarting') {
this.addBanner();
this._handleInfo(this.session.kernel.info);
this._handleInfo(await this.session.kernel.info);
}
}

Expand Down
6 changes: 3 additions & 3 deletions packages/help-extension/src/index.tsx
Expand Up @@ -190,15 +190,15 @@ function activate(
return;
}
const session = serviceManager.sessions.connectTo(sessionModel);
void session.kernel.ready.then(() => {

void session.kernel.info.then(kernelInfo => {
// Check the cache second time so that, if two callbacks get scheduled,
// they don't try to add the same commands.
if (kernelInfoCache.has(sessionModel.kernel.name)) {
return;
}
// Set the Kernel Info cache.
const name = session.kernel.name;
const kernelInfo = session.kernel.info;
kernelInfoCache.set(name, kernelInfo);

// Utility function to check if the current widget
Expand Down Expand Up @@ -265,7 +265,7 @@ function activate(

// Add the kernel info help_links to the Help menu.
const kernelGroup: Menu.IItemOptions[] = [];
(session.kernel.info.help_links || []).forEach(link => {
(kernelInfo.help_links || []).forEach(link => {
const commandId = `help-menu-${name}:${link.text}`;
commands.addCommand(commandId, {
label: link.text,
Expand Down
4 changes: 2 additions & 2 deletions packages/notebook/src/panel.ts
Expand Up @@ -196,9 +196,9 @@ export class NotebookPanel extends DocumentWidget<Notebook, INotebookModel> {
return;
}
let { newValue } = args;
void newValue.ready.then(() => {
void newValue.info.then(info => {
if (this.model && this.context.session.kernel === newValue) {
this._updateLanguage(newValue.info.language_info);
this._updateLanguage(info.language_info);
}
});
void this._updateSpec(newValue);
Expand Down

0 comments on commit b893d5c

Please sign in to comment.