Skip to content

Commit

Permalink
Misc
Browse files Browse the repository at this point in the history
  • Loading branch information
DonJayamanne committed May 18, 2023
1 parent ceb9e79 commit b422016
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions src/kernels/jupyter/connection/jupyterConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,29 +32,23 @@ export class JupyterConnection {
if (!uri) {
throw new Error('Server Not found');
}
return this.createConnectionInfoFromUri(uri);
const server = await this.getJupyterServerUri(uri);
return createRemoteConnectionInfo(uri, server);
}
public async validateJupyterServer(uri: string): Promise<void> {
const connection = await this.createConnectionInfoFromUri(uri);
const disposable: IAsyncDisposable[] = [];
const connection = await this.createConnectionInfo({ uri });
const disposable: IAsyncDisposable[] = [{ dispose: () => Promise.resolve(connection.dispose()) }];
try {
// Attempt to list the running kernels. It will return empty if there are none, but will
// throw if can't connect.
const sessionManager = await this.jupyterSessionManagerFactory.create(connection, false);
disposable.push(sessionManager);
await Promise.all([sessionManager.getRunningKernels(), sessionManager.getKernelSpecs()]);
// We should throw an exception if any of that fails.
} finally {
connection.dispose();
await Promise.all(disposable.map((d) => d.dispose().catch(noop)));
}
}

private async createConnectionInfoFromUri(uri: string) {
const server = await this.getJupyterServerUri(uri);
return createRemoteConnectionInfo(uri, server);
}

private async getJupyterServerUri(uri: string) {
const idAndHandle = extractJupyterServerHandleAndId(uri);
if (!idAndHandle) {
Expand Down

0 comments on commit b422016

Please sign in to comment.