Skip to content

Commit 078896a

Browse files
committed
Update kernel status to have a connection status and a kernel status.
This simplified logic quite a bit. Most of these ideas came from previous work in jupyterlab#4724
1 parent 49fdcfe commit 078896a

File tree

7 files changed

+290
-250
lines changed

7 files changed

+290
-250
lines changed

packages/console/src/widget.ts

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -774,38 +774,23 @@ export class CodeConsole extends Widget {
774774
/**
775775
* Handle a change to the kernel.
776776
*/
777-
private _onKernelChanged(): void {
777+
private async _onKernelChanged(): Promise<void> {
778778
this.clear();
779779
if (this._banner) {
780780
this._banner.dispose();
781781
this._banner = null;
782782
}
783783
this.addBanner();
784+
this._handleInfo(await this.session.kernel.info);
784785
}
785786

786787
/**
787788
* Handle a change to the kernel status.
788789
*/
789-
private _onKernelStatusChanged(): void {
790-
if (this.session.status === 'connected') {
791-
// we just had a kernel restart or reconnect - reset banner
792-
let kernel = this.session.kernel;
793-
if (!kernel) {
794-
return;
795-
}
796-
kernel.ready
797-
.then(() => {
798-
if (this.isDisposed || !kernel || !kernel.info) {
799-
return;
800-
}
801-
this._handleInfo(this.session.kernel.info);
802-
})
803-
.catch(err => {
804-
console.error('could not get kernel info');
805-
});
806-
} else if (this.session.status === 'restarting') {
790+
private async _onKernelStatusChanged(): Promise<void> {
791+
if (this.session.status === 'restarting') {
807792
this.addBanner();
808-
this._handleInfo(this.session.kernel.info);
793+
this._handleInfo(await this.session.kernel.info);
809794
}
810795
}
811796

packages/help-extension/src/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,15 +190,15 @@ function activate(
190190
return;
191191
}
192192
const session = serviceManager.sessions.connectTo(sessionModel);
193-
void session.kernel.ready.then(() => {
193+
194+
void session.kernel.info.then(kernelInfo => {
194195
// Check the cache second time so that, if two callbacks get scheduled,
195196
// they don't try to add the same commands.
196197
if (kernelInfoCache.has(sessionModel.kernel.name)) {
197198
return;
198199
}
199200
// Set the Kernel Info cache.
200201
const name = session.kernel.name;
201-
const kernelInfo = session.kernel.info;
202202
kernelInfoCache.set(name, kernelInfo);
203203

204204
// Utility function to check if the current widget
@@ -265,7 +265,7 @@ function activate(
265265

266266
// Add the kernel info help_links to the Help menu.
267267
const kernelGroup: Menu.IItemOptions[] = [];
268-
(session.kernel.info.help_links || []).forEach(link => {
268+
(kernelInfo.help_links || []).forEach(link => {
269269
const commandId = `help-menu-${name}:${link.text}`;
270270
commands.addCommand(commandId, {
271271
label: link.text,

packages/notebook/src/panel.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,9 @@ export class NotebookPanel extends DocumentWidget<Notebook, INotebookModel> {
196196
return;
197197
}
198198
let { newValue } = args;
199-
void newValue.ready.then(() => {
199+
void newValue.info.then(info => {
200200
if (this.model && this.context.session.kernel === newValue) {
201-
this._updateLanguage(newValue.info.language_info);
201+
this._updateLanguage(info.language_info);
202202
}
203203
});
204204
void this._updateSpec(newValue);

0 commit comments

Comments
 (0)