Skip to content

Commit 7de5b03

Browse files
authored
Make an execution model for just native notebooks (#13480)
* Initial idea * Fix build errors * Fix outputs how VS code likes em * Nightly submit - not working * Fix 13509 - Update display data not being handled * Fix test * Code review feedback * Fix execution count and empty cell test * Fix up after merge * Add some news entries * Fix unit tests
1 parent eb6736f commit 7de5b03

23 files changed

+604
-230
lines changed

news/2 Fixes/13509.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Updating other cells with display.update does not work in native notebooks.

news/2 Fixes/13520.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix for notebook using the first kernel every time. It will now use the language in the notebook to determine the most appropriate kernel.

src/client/datascience/baseJupyterSession.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,22 @@ export abstract class BaseJupyterSession implements IJupyterSession {
6868
public get isConnected(): boolean {
6969
return this.connected;
7070
}
71+
public get onIoPubMessage() {
72+
return this.ioPubEventEmitter.event;
73+
}
7174
protected onStatusChangedEvent: EventEmitter<ServerStatus> = new EventEmitter<ServerStatus>();
7275
protected statusHandler: Slot<ISessionWithSocket, Kernel.Status>;
7376
protected connected: boolean = false;
7477
protected restartSessionPromise: Promise<ISessionWithSocket | undefined> | undefined;
7578
private _session: ISessionWithSocket | undefined;
7679
private _kernelSocket = new ReplaySubject<KernelSocketInformation | undefined>();
7780
private _jupyterLab?: typeof import('@jupyterlab/services');
81+
private ioPubEventEmitter = new EventEmitter<KernelMessage.IIOPubMessage>();
82+
private ioPubHandler: Slot<ISessionWithSocket, KernelMessage.IIOPubMessage>;
7883

7984
constructor(private restartSessionUsed: (id: Kernel.IKernelConnection) => void, public workingDirectory: string) {
8085
this.statusHandler = this.onStatusChanged.bind(this);
86+
this.ioPubHandler = (_s, m) => this.ioPubEventEmitter.fire(m);
8187
}
8288
public dispose(): Promise<void> {
8389
return this.shutdown();
@@ -407,7 +413,13 @@ export abstract class BaseJupyterSession implements IJupyterSession {
407413
// Changes the current session.
408414
protected setSession(session: ISessionWithSocket | undefined) {
409415
const oldSession = this._session;
416+
if (this.ioPubHandler && oldSession) {
417+
oldSession.iopubMessage.disconnect(this.ioPubHandler);
418+
}
410419
this._session = session;
420+
if (session) {
421+
session.iopubMessage.connect(this.ioPubHandler);
422+
}
411423

412424
// If we have a new session, then emit the new kernel connection information.
413425
if (session && oldSession !== session) {

src/client/datascience/jupyter/jupyterNotebook.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,6 @@ export class JupyterNotebookBase implements INotebook {
166166
public get onKernelRestarted(): Event<void> {
167167
return this.kernelRestarted.event;
168168
}
169-
170169
public get onKernelInterrupted(): Event<void> {
171170
return this.kernelInterrupted.event;
172171
}
@@ -179,10 +178,13 @@ export class JupyterNotebookBase implements INotebook {
179178
public get kernelSocket(): Observable<KernelSocketInformation | undefined> {
180179
return this.session.kernelSocket;
181180
}
181+
public get session(): IJupyterSession {
182+
return this._session;
183+
}
182184

183185
constructor(
184186
_liveShare: ILiveShareApi, // This is so the liveshare mixin works
185-
private session: IJupyterSession,
187+
private readonly _session: IJupyterSession,
186188
private configService: IConfigurationService,
187189
private disposableRegistry: IDisposableRegistry,
188190
executionInfo: INotebookExecutionInfo,

0 commit comments

Comments
 (0)