Skip to content

Commit 7846e30

Browse files
authored
Allow interrupting the kernel more than once (#11184)
For #10587, #10356
1 parent d0d356f commit 7846e30

File tree

4 files changed

+35
-27
lines changed

4 files changed

+35
-27
lines changed

news/2 Fixes/10356.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Cancelling the prompt to restart the kernel should not leave the toolbar buttons disabled.

news/2 Fixes/10587.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Allow interrupting the kernel more than once.

src/client/datascience/interactive-common/interactiveBase.ts

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -381,29 +381,40 @@ export abstract class InteractiveBase extends WebViewHost<IInteractiveWindowMapp
381381
}
382382

383383
if (this._notebook && !this.restartingKernel) {
384-
if (await this.shouldAskForRestart()) {
385-
// Ask the user if they want us to restart or not.
386-
const message = localize.DataScience.restartKernelMessage();
387-
const yes = localize.DataScience.restartKernelMessageYes();
388-
const dontAskAgain = localize.DataScience.restartKernelMessageDontAskAgain();
389-
const no = localize.DataScience.restartKernelMessageNo();
390-
391-
const v = await this.applicationShell.showInformationMessage(message, yes, dontAskAgain, no);
392-
if (v === dontAskAgain) {
393-
await this.disableAskForRestart();
394-
await this.restartKernelInternal();
395-
} else if (v === yes) {
384+
this.restartingKernel = true;
385+
this.startProgress();
386+
387+
try {
388+
if (await this.shouldAskForRestart()) {
389+
// Ask the user if they want us to restart or not.
390+
const message = localize.DataScience.restartKernelMessage();
391+
const yes = localize.DataScience.restartKernelMessageYes();
392+
const dontAskAgain = localize.DataScience.restartKernelMessageDontAskAgain();
393+
const no = localize.DataScience.restartKernelMessageNo();
394+
395+
const v = await this.applicationShell.showInformationMessage(message, yes, dontAskAgain, no);
396+
if (v === dontAskAgain) {
397+
await this.disableAskForRestart();
398+
await this.restartKernelInternal();
399+
} else if (v === yes) {
400+
await this.restartKernelInternal();
401+
}
402+
} else {
396403
await this.restartKernelInternal();
397404
}
398-
} else {
399-
await this.restartKernelInternal();
405+
} finally {
406+
this.restartingKernel = false;
407+
this.stopProgress();
400408
}
401409
}
402410
}
403411

404412
@captureTelemetry(Telemetry.Interrupt)
405413
public async interruptKernel(): Promise<void> {
406414
if (this._notebook && !this.restartingKernel) {
415+
this.restartingKernel = true;
416+
this.startProgress();
417+
407418
const status = this.statusProvider.set(
408419
localize.DataScience.interruptKernelStatus(),
409420
true,
@@ -412,10 +423,10 @@ export abstract class InteractiveBase extends WebViewHost<IInteractiveWindowMapp
412423
this
413424
);
414425

415-
const settings = this.configuration.getSettings(await this.getOwningResource());
416-
const interruptTimeout = settings.datascience.jupyterInterruptTimeout;
417-
418426
try {
427+
const settings = this.configuration.getSettings(await this.getOwningResource());
428+
const interruptTimeout = settings.datascience.jupyterInterruptTimeout;
429+
419430
const result = await this._notebook.interruptKernel(interruptTimeout);
420431
status.dispose();
421432

@@ -436,6 +447,9 @@ export abstract class InteractiveBase extends WebViewHost<IInteractiveWindowMapp
436447
status.dispose();
437448
traceError(err);
438449
this.applicationShell.showErrorMessage(err);
450+
} finally {
451+
this.restartingKernel = false;
452+
this.stopProgress();
439453
}
440454
}
441455
}

src/datascience-ui/interactive-common/redux/reducers/kernel.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,13 @@ export namespace Kernel {
2424
export function restartKernel(arg: CommonReducerArg): IMainState {
2525
postActionToExtension(arg, InteractiveWindowMessages.RestartKernel);
2626

27-
// Set busy until kernel is restarted
28-
return {
29-
...arg.prevState,
30-
busy: true
31-
};
27+
return arg.prevState;
3228
}
3329

3430
export function interruptKernel(arg: CommonReducerArg): IMainState {
3531
postActionToExtension(arg, InteractiveWindowMessages.Interrupt);
3632

37-
// Set busy until kernel is finished interrupting
38-
return {
39-
...arg.prevState,
40-
busy: true
41-
};
33+
return arg.prevState;
4234
}
4335

4436
export function updateStatus(

0 commit comments

Comments
 (0)