Skip to content

Commit

Permalink
Add kernel monitoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alan Fleming committed Sep 8, 2024
1 parent 66a2d33 commit 63e47d3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
8 changes: 8 additions & 0 deletions python/jupyterlab_widgets/src/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ export abstract class LabWidgetManager
super.disconnect();
this._restoredStatus = false;
}
get disconnected() {
return !this._restoredStatus;
}

protected async _loadFromKernel(): Promise<void> {
if (!this.kernel) {
Expand Down Expand Up @@ -471,6 +474,11 @@ export class KernelWidgetManager extends LabWidgetManager {
}
}

static existsWithActiveKenel(id: string) {
const widgetManager = Private.kernelWidgetManagers.get(id);
return !widgetManager?.disconnected;
}

_handleKernelStatusChange(
sender: Kernel.IKernelConnection,
status: Kernel.Status
Expand Down
17 changes: 17 additions & 0 deletions python/jupyterlab_widgets/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { DisposableDelegate } from '@lumino/disposable';
import { WidgetRenderer } from './renderer';

import {
KernelWidgetManager,
LabWidgetManager,
WIDGET_VIEW_MIMETYPE,
WidgetManager,
Expand Down Expand Up @@ -103,6 +104,22 @@ function activateWidgetExtension(
const { commands } = app;
const trans = (translator ?? nullTranslator).load('jupyterlab_widgets');

app.serviceManager.kernels.runningChanged.connect((models) => {
for (const model of models.running()) {
if (
model &&
model.name === 'python3' &&
model.execution_state !== 'starting' &&
!KernelWidgetManager.existsWithActiveKenel(model.id)
) {
const kernel = app.serviceManager.kernels.connectTo({ model: model });
if (kernel.handleComms) {
new KernelWidgetManager(kernel);
}
}
}
});

if (settingRegistry !== null) {
settingRegistry
.load(managerPlugin.id)
Expand Down

0 comments on commit 63e47d3

Please sign in to comment.