Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
pwang347 committed Nov 26, 2024
1 parent dbd78ca commit 4721198
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/kernels/kernel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,10 @@ abstract class BaseKernel implements IBaseKernel {
public get restarting() {
return this._restartPromise || Promise.resolve();
}
private _postInitializingDeferred = createDeferred<void>();
public get postInitializing() {
return this._postInitializingDeferred.promise;
}
constructor(
public readonly id: string,
public readonly uri: Uri,
Expand Down Expand Up @@ -258,9 +262,14 @@ abstract class BaseKernel implements IBaseKernel {
// If we started and the UI is no longer disabled (ie., a user executed a cell)
// then we can signal that the kernel was created and can be used by third-party extensions.
// We also only want to fire off a single event here.
if (!options?.disableUI && !this._postInitializedOnStart) {
if (!this.startupUI.disableUI && !this._postInitializedOnStart) {
this._onPostInitialized.fire();
this._postInitializedOnStart = true;
// Inject a small delay to allow external event handlers a brief window
// to queue code executions.
setTimeout(() => {
this._postInitializingDeferred.resolve();
}, 50);
}
return result;
});
Expand Down
5 changes: 5 additions & 0 deletions src/kernels/kernelExecution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,13 @@ export class NotebookKernelExecution implements INotebookKernelExecution {
const sessionPromise = this.kernel.restarting.then(() => this.kernel.start(new DisplayOptions(false)));

traceCellMessage(cell, `NotebookKernelExecution.executeCell (3), ${getDisplayPath(cell.notebook.uri)}`);

// Wait for the kernel to complete post initialization before queueing the cell in case
// we need to allow extensions to run code before the initial user-triggered execution
await this.kernel.postInitializing;
const executionQueue = this.getOrCreateCellExecutionQueue(cell.notebook, sessionPromise);
executionQueue.queueCell(cell, codeOverride);

let success = true;
try {
traceCellMessage(cell, `NotebookKernelExecution.executeCell (4), ${getDisplayPath(cell.notebook.uri)}`);
Expand Down
1 change: 1 addition & 0 deletions src/kernels/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ export interface IBaseKernel extends IAsyncDisposable {
readonly onRestarted: Event<void>;
readonly onPostInitialized: Event<void>;
readonly restarting: Promise<void>;
readonly postInitializing: Promise<void>;
readonly status: KernelMessage.Status;
readonly disposed: boolean;
readonly disposing: boolean;
Expand Down

0 comments on commit 4721198

Please sign in to comment.