Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/wapython
Path: blob/main/desktop/electron/src/python.ts
1067 views
1
import debug from "debug";
2
import { asyncPython } from "python-wasm";
3
4
// TODO: will get exported in future version of python-wasm.
5
type PythonWasmAsync = Awaited<ReturnType<typeof asyncPython>>;
6
7
const log = debug("python");
8
9
let python: PythonWasmAsync | null = null;
10
11
// todo: reuseInFlight...?
12
export default async function getPython() {
13
if (python == null) {
14
// Very important to explicitly set the fs, since that's not the default yet.
15
python = await asyncPython({ noStdio: true, fs: "everything" });
16
}
17
return python;
18
}
19
20
export function pythonTerminate() {
21
if (python == null) return;
22
const kernel = python.kernel;
23
python = null;
24
kernel.terminate();
25
}
26
27