-
Notifications
You must be signed in to change notification settings - Fork 295
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
51fad38
commit edb849d
Showing
18 changed files
with
637 additions
and
322 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
import type { Kernel } from '@jupyterlab/services'; | ||
import { IDisposable } from '../../platform/common/types'; | ||
import { BaseKernelConnectionWrapper } from '../jupyter/baseKernelConnectionWrapper'; | ||
|
||
export class KernelConnectionWrapper extends BaseKernelConnectionWrapper { | ||
/** | ||
* Use `kernelConnection` to access the value as its not a constant (can change over time). | ||
* E.g. when restarting kernels or the like. | ||
*/ | ||
private _kernelConnection!: Kernel.IKernelConnection; | ||
protected get possibleKernelConnection(): undefined | Kernel.IKernelConnection { | ||
return this._kernelConnection; | ||
} | ||
public get kernel() { | ||
return this._kernelConnection; | ||
} | ||
|
||
constructor(kernel: Kernel.IKernelConnection, disposables: IDisposable[]) { | ||
super(kernel, disposables); | ||
this._kernelConnection = kernel; | ||
} | ||
public changeKernel(kernel: Kernel.IKernelConnection) { | ||
if (this.kernel === kernel) { | ||
return; | ||
} | ||
this.stopHandlingKernelMessages(this.possibleKernelConnection!); | ||
this._kernelConnection = kernel; | ||
this.startHandleKernelMessages(kernel); | ||
} | ||
async shutdown(): Promise<void> { | ||
await this._kernelConnection.shutdown(); | ||
} | ||
dispose(): void { | ||
this._kernelConnection.dispose(); | ||
} | ||
async interrupt(): Promise<void> { | ||
await this._kernelConnection.interrupt(); | ||
} | ||
async restart(): Promise<void> { | ||
await this._kernelConnection.restart(); | ||
} | ||
protected override startHandleKernelMessages(kernelConnection: Kernel.IKernelConnection) { | ||
super.startHandleKernelMessages(kernelConnection); | ||
this._kernelConnection = kernelConnection; | ||
kernelConnection.connectionStatusChanged.connect(this.onConnectionStatusChanged, this); | ||
kernelConnection.statusChanged.connect(this.onStatusChanged, this); | ||
kernelConnection.disposed.connect(this.onDisposed, this); | ||
} | ||
protected override stopHandlingKernelMessages(kernelConnection: Kernel.IKernelConnection): void { | ||
super.stopHandlingKernelMessages(kernelConnection); | ||
kernelConnection.connectionStatusChanged.disconnect(this.onConnectionStatusChanged, this); | ||
kernelConnection.statusChanged.disconnect(this.onStatusChanged, this); | ||
kernelConnection.disposed.disconnect(this.onDisposed, this); | ||
} | ||
private onDisposed(connection: Kernel.IKernelConnection) { | ||
if (connection === this.possibleKernelConnection) { | ||
this.disposed.emit(); | ||
} | ||
} | ||
private onStatusChanged(connection: Kernel.IKernelConnection, args: Kernel.Status) { | ||
if (connection === this.possibleKernelConnection) { | ||
this.statusChanged.emit(args); | ||
} | ||
} | ||
private onConnectionStatusChanged(connection: Kernel.IKernelConnection, args: Kernel.ConnectionStatus) { | ||
if (connection === this.possibleKernelConnection) { | ||
this.connectionStatusChanged.emit(args); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.