Skip to content

Commit

Permalink
misc
Browse files Browse the repository at this point in the history
  • Loading branch information
DonJayamanne committed Oct 5, 2021
1 parent c8d87c0 commit d5cedec
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 63 deletions.
73 changes: 25 additions & 48 deletions src/client/datascience/commands/activeEditorContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,58 +160,35 @@ export class ActiveEditorContextService implements IExtensionSingleActivationSer
}
private updateContextOfActiveNotebookKernel(activeEditor?: NotebookEditor) {
if (activeEditor && activeEditor.document.notebookType === JupyterNotebookView) {
this.notebookProvider
.getOrCreateNotebook({
identity: activeEditor.document.uri,
resource: activeEditor.document.uri,
getOnly: true
})
.then(async (nb) => {
if (activeEditor === this.vscNotebook.activeNotebookEditor) {
const canStart = nb && nb.status !== ServerStatus.NotStarted;
this.canRestartNotebookKernelContext.set(!!canStart).ignoreErrors();
}
})
.catch(
traceError.bind(undefined, 'Failed to determine if a notebook is active for the current editor')
);
const hasPendingCells = this.kernelProvider.get(activeEditor.document)?.hasPendingCells === true;
this.canInterruptNotebookKernelContext.set(hasPendingCells).ignoreErrors();
} else {
this.canRestartNotebookKernelContext.set(false).ignoreErrors();
this.canInterruptNotebookKernelContext.set(false).ignoreErrors();
const kernel = this.kernelProvider.get(activeEditor.document);
if (kernel) {
const canStart = kernel.status !== ServerStatus.NotStarted;
this.canRestartNotebookKernelContext.set(!!canStart).ignoreErrors();
const canInterrupt = kernel.status === ServerStatus.Busy;
const hasPendingCells = this.kernelProvider.get(activeEditor.document)?.hasPendingCells === true;
this.canInterruptNotebookKernelContext.set(canInterrupt || hasPendingCells).ignoreErrors();
return;
}
}
this.canRestartNotebookKernelContext.set(false).ignoreErrors();
this.canInterruptNotebookKernelContext.set(false).ignoreErrors();
}
private updateContextOfActiveInteractiveWindowKernel() {
const interactiveWindow = getActiveInteractiveWindow(this.interactiveProvider);
if (interactiveWindow?.notebookUri) {
this.notebookProvider
.getOrCreateNotebook({
identity: interactiveWindow.notebookUri,
resource: interactiveWindow.owner,
getOnly: true
})
.then(async (nb) => {
if (
getActiveInteractiveWindow(this.interactiveProvider) === interactiveWindow &&
nb !== undefined
) {
const canStart = nb && nb.status !== ServerStatus.NotStarted;
this.canRestartInteractiveWindowKernelContext.set(!!canStart).ignoreErrors();
const canInterrupt = nb && nb.status === ServerStatus.Busy;
this.canInterruptInteractiveWindowKernelContext.set(!!canInterrupt).ignoreErrors();
}
})
.catch(
traceError.bind(
undefined,
'Failed to determine if a kernel is active for the current interactive window'
)
);
} else {
this.canRestartInteractiveWindowKernelContext.set(false).ignoreErrors();
this.canInterruptInteractiveWindowKernelContext.set(false).ignoreErrors();
const notebook = interactiveWindow?.notebookEditor?.document;
if (notebook) {
const kernel = this.kernelProvider.get(notebook);
if (kernel) {
const canStart = kernel.status !== ServerStatus.NotStarted;
this.canRestartInteractiveWindowKernelContext.set(!!canStart).ignoreErrors();
const canInterrupt = kernel.status === ServerStatus.Busy;
const hasPendingCells = this.kernelProvider.get(notebook)?.hasPendingCells === true;
this.canInterruptInteractiveWindowKernelContext.set(canInterrupt || hasPendingCells).ignoreErrors();
return;
}
}
this.canRestartInteractiveWindowKernelContext.set(false).ignoreErrors();
this.canInterruptInteractiveWindowKernelContext.set(false).ignoreErrors();
}
private onDidKernelStatusChange({ notebook }: { status: ServerStatus; notebook: INotebook }) {
// Ok, kernel status has changed.
Expand Down Expand Up @@ -245,7 +222,7 @@ export class ActiveEditorContextService implements IExtensionSingleActivationSer
this.pythonOrInteractiveOrNativeContext
.set(
this.nativeContext.value === true ||
(this.interactiveContext.value === true && this.isPythonFileActive === true)
(this.interactiveContext.value === true && this.isPythonFileActive === true)
)
.ignoreErrors();
}
Expand Down
28 changes: 13 additions & 15 deletions src/client/datascience/jupyter/kernels/kernelExecution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,22 +70,20 @@ export class KernelExecution implements IDisposable {
// If we're in the middle of restarting, ensure we properly have the state of has pending cells.
this._hasPendingCells = true;

try {
// If we're restarting, wait for it to finish
if (this._restartPromise) {
await this._restartPromise;
}
if (cell.notebook.notebookType === InteractiveWindowView) {
await this.cellHashProviderFactory.getOrCreate(this.kernel).addCellHash(cell);
}

const executionQueue = this.getOrCreateCellExecutionQueue(cell.notebook, notebookPromise);
executionQueue.queueCell(cell);
const result = await executionQueue.waitForCompletion([cell]);
return result[0];
} finally {
this._hasPendingCells = false;
// If we're restarting, wait for it to finish
if (this._restartPromise) {
await this._restartPromise;
}
if (cell.notebook.notebookType === InteractiveWindowView) {
await this.cellHashProviderFactory.getOrCreate(this.kernel).addCellHash(cell);
}

const executionQueue = this.getOrCreateCellExecutionQueue(cell.notebook, notebookPromise);
executionQueue.queueCell(cell);
// Once we've queued the cell, then the queue will tell us whether we have any pending cells or not.
this._hasPendingCells = false;
const result = await executionQueue.waitForCompletion([cell]);
return result[0];
}

/**
Expand Down

0 comments on commit d5cedec

Please sign in to comment.