Skip to content
This repository has been archived by the owner on Jan 26, 2022. It is now read-only.

Commit

Permalink
Improve kernel restarts handling
Browse files Browse the repository at this point in the history
  • Loading branch information
jtpio committed Jan 17, 2020
1 parent b267d4a commit f070d19
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { FileEditor } from '@jupyterlab/fileeditor';

import { NotebookPanel } from '@jupyterlab/notebook';

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

import { DebuggerModel } from './model';

Expand Down Expand Up @@ -100,18 +100,13 @@ export class DebuggerHandler {
this._kernelChangedHandlers[connection.path] = updateHandler;

// setup handler when the status of the kernel changes (restart)
// TODO: is there a better way to handle restarts?
let restarted = false;
const statusChanged = async () => {
// wait for the first `idle` status after a restart
if (restarted && connection.kernel?.status === 'idle') {
restarted = false;
const statusChanged = async (
sender: Session.ISessionConnection,
status: Kernel.Status
) => {
if (status.endsWith('restarting')) {
return updateHandler();
}
// handle `starting`, `restarting` and `autorestarting`
if (connection.kernel?.status.endsWith('starting')) {
restarted = true;
}
};

const statusChangedHandler = this._statusChangedHandlers[connection.path];
Expand Down Expand Up @@ -271,7 +266,12 @@ export class DebuggerHandler {
[id: string]: DebuggerHandler.SessionHandler[DebuggerHandler.SessionType];
} = {};
private _kernelChangedHandlers: { [id: string]: () => void } = {};
private _statusChangedHandlers: { [id: string]: () => void } = {};
private _statusChangedHandlers: {
[id: string]: (
sender: Session.ISessionConnection,
status: Kernel.Status
) => void;
} = {};
private _buttons: { [id: string]: ToolbarButton } = {};
}

Expand Down

0 comments on commit f070d19

Please sign in to comment.