Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/jupyter/kernel/test/util.ts
1450 views
1
import { kernel, type JupyterKernel } from "../kernel";
2
import { getPythonKernelName } from "../kernel-data";
3
4
const usedNames = new Set<string>();
5
const kernels: JupyterKernel[] = [];
6
export async function getPythonKernel(
7
path: string,
8
noCheck = false,
9
): Promise<JupyterKernel> {
10
if (!noCheck && usedNames.has(path)) {
11
throw Error(`do not reuse names as that is very confusing -- ${path}`);
12
}
13
usedNames.add(path);
14
const k = kernel({ name: await getPythonKernelName(), path });
15
kernels.push(k);
16
return k;
17
}
18
19
export function closeKernels() {
20
kernels.map((k) => k.close());
21
}
22