Skip to content

Commit dbad325

Browse files
authored
Reject kernel ready promise when disposed (#238)
* use a promise lock to serialize remote kernel initialization * handle disposing * avoid trying to initialize if already disposed * remove init lock, leave promise rejection
1 parent 3e1a10c commit dbad325

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

packages/pyodide-kernel/src/kernel.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ import { PromiseDelegate } from '@lumino/coreutils';
66

77
import { PageConfig } from '@jupyterlab/coreutils';
88

9-
import { ILogPayload } from '@jupyterlab/logconsole';
9+
import type { ILogPayload } from '@jupyterlab/logconsole';
1010

1111
import { Contents, KernelMessage } from '@jupyterlab/services';
1212

1313
import { BaseKernel, IKernel } from '@jupyterlite/kernel';
1414

15-
import {
15+
import type {
1616
ICoincidentPyodideWorkerKernel,
1717
IComlinkPyodideKernel,
1818
IPyodideWorkerKernel,
@@ -123,6 +123,7 @@ export class PyodideKernel extends BaseKernel implements IKernel {
123123
});
124124
}
125125
const remoteOptions = this.initRemoteOptions(options);
126+
126127
remote
127128
.initialize(remoteOptions)
128129
.then(this._ready.resolve.bind(this._ready))
@@ -131,6 +132,7 @@ export class PyodideKernel extends BaseKernel implements IKernel {
131132
payload: { type: 'text', level: 'critical', data: err.message },
132133
kernelId: this.id,
133134
});
135+
this._ready.reject(err.message);
134136
});
135137
return remote;
136138
}
@@ -168,6 +170,11 @@ export class PyodideKernel extends BaseKernel implements IKernel {
168170
if (this.isDisposed) {
169171
return;
170172
}
173+
try {
174+
this._ready.reject(`${this.id} was disposed`);
175+
} catch (err) {
176+
// nothing to see here
177+
}
171178
this._worker.terminate();
172179
(this._worker as any) = null;
173180
super.dispose();

0 commit comments

Comments
 (0)