Skip to content

Commit 7f44848

Browse files
Raw kernel auto start fix + (microsoft#12337)
1 parent 92e9f7a commit 7f44848

13 files changed

Lines changed: 44 additions & 70 deletions

File tree

news/2 Fixes/12330.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix raw kernel autostart and remove jupyter execution from interactive base.

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

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ import {
8080
IInteractiveWindowInfo,
8181
IInteractiveWindowListener,
8282
IJupyterDebugger,
83-
IJupyterExecution,
8483
IJupyterKernelSpec,
8584
IJupyterVariableDataProviderFactory,
8685
IJupyterVariables,
@@ -134,7 +133,6 @@ export abstract class InteractiveBase extends WebViewHost<IInteractiveWindowMapp
134133
@unmanaged() cssGenerator: ICodeCssGenerator,
135134
@unmanaged() themeFinder: IThemeFinder,
136135
@unmanaged() private statusProvider: IStatusProvider,
137-
@unmanaged() protected jupyterExecution: IJupyterExecution,
138136
@unmanaged() protected fileSystem: IFileSystem,
139137
@unmanaged() protected configuration: IConfigurationService,
140138
@unmanaged() protected jupyterExporter: INotebookExporter,
@@ -178,9 +176,6 @@ export abstract class InteractiveBase extends WebViewHost<IInteractiveWindowMapp
178176
const handler = this.documentManager.onDidChangeActiveTextEditor(() => this.activating());
179177
this.disposables.push(handler);
180178

181-
// If our execution changes its liveshare session, we need to close our server
182-
this.jupyterExecution.sessionChanged(() => this.reloadAfterShutdown());
183-
184179
// For each listener sign up for their post events
185180
this.listeners.forEach((l) => l.postMessage((e) => this.postMessageInternal(e.message, e.payload)));
186181
// Channel for listeners to send messages to the interactive base.
@@ -199,8 +194,8 @@ export abstract class InteractiveBase extends WebViewHost<IInteractiveWindowMapp
199194
.ignoreErrors();
200195
}, 0);
201196

202-
// When a server starts, make sure we create a notebook if the server matches
203-
jupyterExecution.serverStarted(this.checkForNotebookProviderConnection.bind(this));
197+
// When a notebook provider first makes its connection check it to see if we should create a notebook
198+
this.disposables.push(notebookProvider.onConnectionMade(this.checkForNotebookProviderConnection.bind(this)));
204199

205200
// When the variable service requests a refresh, refresh our variable list
206201
this.disposables.push(this.jupyterVariables.refreshRequired(this.refreshVariables.bind(this)));
@@ -1046,27 +1041,6 @@ export abstract class InteractiveBase extends WebViewHost<IInteractiveWindowMapp
10461041
sendTelemetryEvent(event);
10471042
};
10481043

1049-
private async stopServer(): Promise<void> {
1050-
// Finish either of our notebook promises
1051-
if (this.connectionAndNotebookPromise) {
1052-
await this.connectionAndNotebookPromise;
1053-
this.connectionAndNotebookPromise = undefined;
1054-
}
1055-
if (this.notebookPromise) {
1056-
await this.notebookPromise;
1057-
this.notebookPromise = undefined;
1058-
}
1059-
// If we have a notebook dispose of it
1060-
if (this._notebook) {
1061-
const notebook = this._notebook;
1062-
this._notebook = undefined;
1063-
await notebook.dispose();
1064-
}
1065-
1066-
// Disconnect from our notebook provider
1067-
await this.notebookProvider.disconnect({ getOnly: true });
1068-
}
1069-
10701044
// ensureNotebook can be called apart from ensureNotebookAndServer and it needs
10711045
// the same protection to not be called twice
10721046
// tslint:disable-next-line: member-ordering
@@ -1205,20 +1179,6 @@ export abstract class InteractiveBase extends WebViewHost<IInteractiveWindowMapp
12051179
}
12061180
}
12071181

1208-
private async reloadAfterShutdown(): Promise<void> {
1209-
try {
1210-
await this.stopServer();
1211-
} catch {
1212-
// We just switched from host to guest mode. Don't really care
1213-
// if closing the host server kills it.
1214-
this._notebook = undefined;
1215-
} finally {
1216-
this.connectionAndNotebookPromise = undefined;
1217-
this.notebookPromise = undefined;
1218-
}
1219-
await this.ensureConnectionAndNotebook();
1220-
}
1221-
12221182
@captureTelemetry(Telemetry.GotoSourceCode, undefined, false)
12231183
private gotoCode(args: IGotoCode) {
12241184
this.gotoCodeInternal(args.file, args.line).catch((err) => {

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
export class NotebookProvider implements INotebookProvider {
2929
private readonly notebooks = new Map<string, Promise<INotebook>>();
3030
private _notebookCreated = new EventEmitter<{ identity: Uri; notebook: INotebook }>();
31+
private _connectionMade = new EventEmitter<void>();
3132
private _type: 'jupyter' | 'raw' = 'jupyter';
3233
public get activeNotebooks() {
3334
return [...this.notebooks.values()];
@@ -56,6 +57,10 @@ export class NotebookProvider implements INotebookProvider {
5657
return this._notebookCreated.event;
5758
}
5859

60+
public get onConnectionMade() {
61+
return this._connectionMade.event;
62+
}
63+
5964
public get type(): 'jupyter' | 'raw' {
6065
return this._type;
6166
}
@@ -72,9 +77,15 @@ export class NotebookProvider implements INotebookProvider {
7277
public async connect(options: ConnectNotebookProviderOptions): Promise<INotebookProviderConnection | undefined> {
7378
// Connect to either a jupyter server or a stubbed out raw notebook "connection"
7479
if (await this.rawNotebookProvider.supported()) {
75-
return this.rawNotebookProvider.connect(options);
80+
return this.rawNotebookProvider.connect({
81+
...options,
82+
onConnectionMade: this.fireConnectionMade.bind(this)
83+
});
7684
} else {
77-
return this.jupyterNotebookProvider.connect(options);
85+
return this.jupyterNotebookProvider.connect({
86+
...options,
87+
onConnectionMade: this.fireConnectionMade.bind(this)
88+
});
7889
}
7990
}
8091

@@ -134,6 +145,10 @@ export class NotebookProvider implements INotebookProvider {
134145
return promise;
135146
}
136147

148+
private fireConnectionMade() {
149+
this._connectionMade.fire();
150+
}
151+
137152
// Cache the promise that will return a notebook
138153
private cacheNotebookPromise(identity: Uri, promise: Promise<INotebook>) {
139154
this.notebooks.set(identity.fsPath, promise);

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,14 @@ export class NotebookServerProvider implements IJupyterServerProvider {
5353
return this.jupyterExecution.getServer(serverOptions);
5454
} else {
5555
// Otherwise create a new server
56-
return this.createServer(options, token);
56+
return this.createServer(options, token).then((val) => {
57+
// If we created a new server notify of our first time provider connection
58+
if (val && options.onConnectionMade) {
59+
options.onConnectionMade();
60+
}
61+
62+
return val;
63+
});
5764
}
5865
}
5966

src/client/datascience/interactive-ipynb/nativeEditor.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ import {
6666
IInteractiveWindowInfo,
6767
IInteractiveWindowListener,
6868
IJupyterDebugger,
69-
IJupyterExecution,
7069
IJupyterKernelSpec,
7170
IJupyterVariableDataProviderFactory,
7271
IJupyterVariables,
@@ -160,7 +159,6 @@ export class NativeEditor extends InteractiveBase implements INotebookEditor {
160159
@inject(ICodeCssGenerator) cssGenerator: ICodeCssGenerator,
161160
@inject(IThemeFinder) themeFinder: IThemeFinder,
162161
@inject(IStatusProvider) statusProvider: IStatusProvider,
163-
@inject(IJupyterExecution) jupyterExecution: IJupyterExecution,
164162
@inject(IFileSystem) fileSystem: IFileSystem,
165163
@inject(IConfigurationService) configuration: IConfigurationService,
166164
@inject(ICommandManager) commandManager: ICommandManager,
@@ -193,7 +191,6 @@ export class NativeEditor extends InteractiveBase implements INotebookEditor {
193191
cssGenerator,
194192
themeFinder,
195193
statusProvider,
196-
jupyterExecution,
197194
fileSystem,
198195
configuration,
199196
jupyterExporter,

src/client/datascience/interactive-ipynb/nativeEditorOldWebView.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ import {
3939
IDataScienceErrorHandler,
4040
IInteractiveWindowListener,
4141
IJupyterDebugger,
42-
IJupyterExecution,
4342
IJupyterVariableDataProviderFactory,
4443
IJupyterVariables,
4544
INotebookEditorProvider,
@@ -81,7 +80,6 @@ export class NativeEditorOldWebView extends NativeEditor {
8180
@inject(ICodeCssGenerator) cssGenerator: ICodeCssGenerator,
8281
@inject(IThemeFinder) themeFinder: IThemeFinder,
8382
@inject(IStatusProvider) statusProvider: IStatusProvider,
84-
@inject(IJupyterExecution) jupyterExecution: IJupyterExecution,
8583
@inject(IFileSystem) fileSystem: IFileSystem,
8684
@inject(IConfigurationService) configuration: IConfigurationService,
8785
@inject(ICommandManager) commandManager: ICommandManager,
@@ -115,7 +113,6 @@ export class NativeEditorOldWebView extends NativeEditor {
115113
cssGenerator,
116114
themeFinder,
117115
statusProvider,
118-
jupyterExecution,
119116
fileSystem,
120117
configuration,
121118
commandManager,

src/client/datascience/interactive-window/interactiveWindow.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ import {
5252
IInteractiveWindowListener,
5353
IInteractiveWindowProvider,
5454
IJupyterDebugger,
55-
IJupyterExecution,
5655
IJupyterKernelSpec,
5756
IJupyterVariableDataProviderFactory,
5857
IJupyterVariables,
@@ -96,7 +95,6 @@ export class InteractiveWindow extends InteractiveBase implements IInteractiveWi
9695
@inject(IDisposableRegistry) disposables: IDisposableRegistry,
9796
@inject(ICodeCssGenerator) cssGenerator: ICodeCssGenerator,
9897
@inject(IThemeFinder) themeFinder: IThemeFinder,
99-
@inject(IJupyterExecution) jupyterExecution: IJupyterExecution,
10098
@inject(IFileSystem) fileSystem: IFileSystem,
10199
@inject(IConfigurationService) configuration: IConfigurationService,
102100
@inject(ICommandManager) commandManager: ICommandManager,
@@ -127,7 +125,6 @@ export class InteractiveWindow extends InteractiveBase implements IInteractiveWi
127125
cssGenerator,
128126
themeFinder,
129127
statusProvider,
130-
jupyterExecution,
131128
fileSystem,
132129
configuration,
133130
jupyterExporter,

src/client/datascience/jupyter/jupyterExecution.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ const LocalHosts = ['localhost', '127.0.0.1', '::1'];
3939

4040
export class JupyterExecutionBase implements IJupyterExecution {
4141
private usablePythonInterpreter: PythonInterpreter | undefined;
42-
private eventEmitter: EventEmitter<void> = new EventEmitter<void>();
4342
private startedEmitter: EventEmitter<INotebookServerOptions> = new EventEmitter<INotebookServerOptions>();
4443
private disposed: boolean = false;
4544
private readonly jupyterInterpreterService: IJupyterSubCommandExecutionService;
@@ -73,10 +72,6 @@ export class JupyterExecutionBase implements IJupyterExecution {
7372
}
7473
}
7574

76-
public get sessionChanged(): Event<void> {
77-
return this.eventEmitter.event;
78-
}
79-
8075
public get serverStarted(): Event<INotebookServerOptions> {
8176
return this.startedEmitter.event;
8277
}

src/client/datascience/raw-kernel/rawNotebookProvider.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ export class RawNotebookProviderBase implements IRawNotebookProvider {
6363
// If not get only, create if needed and return
6464
if (!this.rawConnection) {
6565
this.rawConnection = new RawConnection();
66+
67+
// Fire our optional event that we have created a connection
68+
if (options.onConnectionMade) {
69+
options.onConnectionMade();
70+
}
6671
}
6772
return Promise.resolve(this.rawConnection);
6873
}

src/client/datascience/types.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ export type ConnectNotebookProviderOptions = {
243243
disableUI?: boolean;
244244
localOnly?: boolean;
245245
token?: CancellationToken;
246+
onConnectionMade?(): void; // Optional callback for when the first connection is made
246247
};
247248

248249
export interface INotebookServerOptions {
@@ -280,7 +281,6 @@ export interface IGatherLogger extends INotebookExecutionLogger {
280281

281282
export const IJupyterExecution = Symbol('IJupyterExecution');
282283
export interface IJupyterExecution extends IAsyncDisposable {
283-
sessionChanged: Event<void>;
284284
serverStarted: Event<INotebookServerOptions | undefined>;
285285
isNotebookSupported(cancelToken?: CancellationToken): Promise<boolean>;
286286
isImportSupported(cancelToken?: CancellationToken): Promise<boolean>;
@@ -1052,6 +1052,7 @@ export type GetServerOptions = {
10521052
disableUI?: boolean;
10531053
localOnly?: boolean;
10541054
token?: CancellationToken;
1055+
onConnectionMade?(): void; // Optional callback for when the first connection is made
10551056
};
10561057

10571058
/**
@@ -1073,6 +1074,11 @@ export interface INotebookProvider {
10731074
*/
10741075
onNotebookCreated: Event<{ identity: Uri; notebook: INotebook }>;
10751076

1077+
/**
1078+
* Fired just the first time that this provider connects
1079+
*/
1080+
onConnectionMade: Event<void>;
1081+
10761082
/**
10771083
* List of all notebooks (active and ones that are being constructed).
10781084
*/

0 commit comments

Comments
 (0)