Skip to content

Commit fe3d415

Browse files
Don't start two notebooks when interactive window starts (#9835)
1 parent 77bc1f6 commit fe3d415

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

news/2 Fixes/9780.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix debugging of Interactive Window cells. Don't start up a second notebook at Interactive Window startup.

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

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ export abstract class InteractiveBase extends WebViewHost<IInteractiveWindowMapp
8484
private _id: string;
8585
private executeEvent: EventEmitter<string> = new EventEmitter<string>();
8686
private serverAndNotebookPromise: Promise<void> | undefined;
87+
private notebookPromise: Promise<void> | undefined;
8788
private setDarkPromise: Deferred<boolean> | undefined;
8889
public get notebook(): INotebook | undefined {
8990
return this._notebook;
@@ -936,18 +937,39 @@ export abstract class InteractiveBase extends WebViewHost<IInteractiveWindowMapp
936937
};
937938

938939
private async stopServer(): Promise<void> {
940+
// Finish either of our notebook promises
939941
if (this.serverAndNotebookPromise) {
940942
await this.serverAndNotebookPromise;
941943
this.serverAndNotebookPromise = undefined;
942-
if (this._notebook) {
943-
const server = this._notebook;
944-
this._notebook = undefined;
945-
await server.dispose();
946-
}
944+
}
945+
if (this.notebookPromise) {
946+
await this.notebookPromise;
947+
this.notebookPromise = undefined;
948+
}
949+
// If we have a notebook dispose of it
950+
if (this._notebook) {
951+
const server = this._notebook;
952+
this._notebook = undefined;
953+
await server.dispose();
947954
}
948955
}
949956

957+
// ensureNotebook can be called apart from ensureNotebookAndServer and it needs
958+
// the same protection to not be called twice
950959
private async ensureNotebook(server: INotebookServer): Promise<void> {
960+
if (!this.notebookPromise) {
961+
this.notebookPromise = this.ensureNotebookImpl(server);
962+
}
963+
try {
964+
await this.notebookPromise;
965+
} catch (e) {
966+
// Reset the load promise. Don't want to keep hitting the same error
967+
this.notebookPromise = undefined;
968+
throw e;
969+
}
970+
}
971+
972+
private async ensureNotebookImpl(server: INotebookServer): Promise<void> {
951973
// Create a new notebook if we need to.
952974
if (!this._notebook) {
953975
this._notebook = await server.createNotebook(await this.getNotebookIdentity());
@@ -1019,6 +1041,7 @@ export abstract class InteractiveBase extends WebViewHost<IInteractiveWindowMapp
10191041
this._notebook = undefined;
10201042
} finally {
10211043
this.serverAndNotebookPromise = undefined;
1044+
this.notebookPromise = undefined;
10221045
}
10231046
await this.ensureServerAndNotebook();
10241047
}

0 commit comments

Comments
 (0)