This repository has been archived by the owner on Mar 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnew_fib.js
61 lines (45 loc) · 1.68 KB
/
new_fib.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
var xmlhttprequest = require("xmlhttprequest");
var ws = require("ws");
var fs = require("fs");
global.XMLHttpRequest = xmlhttprequest.XMLHttpRequest;
global.WebSocket = ws;
var jupyter = require("@jupyterlab/services");
var gatewayUrl = process.env.BASE_GATEWAY_HTTP_URL || "http://localhost:8888";
var gatewayWsUrl = process.env.BASE_GATEWAY_WS_URL || "ws://localhost:8888";
var demoLang = process.env.DEMO_LANG || "python3";
var demoInfo = {
python3: {
kernelName: "python3",
filename: "test_fib.py",
},
}[demoLang];
var demoSrc = fs.readFileSync(demoInfo.filename, { encoding: "utf-8" });
console.log("Targeting server:", gatewayUrl);
console.log("Using example code:", demoInfo.filename);
var ajaxSettings = {};
// For authentication, set the environment variables:
// BASE_GATEWAY_USERNAME and BASE_GATEWAY_PASSWORD.
if (process.env.BASE_GATEWAY_USERNAME) {
ajaxSettings["user"] = process.env.BASE_GATEWAY_USERNAME;
}
if (process.env.BASE_GATEWAY_PASSWORD) {
ajaxSettings["password"] = process.env.BASE_GATEWAY_PASSWORD;
}
console.log("ajaxSettings: ", ajaxSettings);
const settings = jupyter.ServerConnection.makeSettings({
baseUrl: gatewayUrl,
wsUrl: gatewayWsUrl,
});
const kernelManager = new jupyter.KernelManager({
serverSettings: settings,
});
(async () => {
const kernel = await kernelManager.startNew({ name: "python3" });
kernel.statusChanged.connect((_, status) => console.log(status));
const future = kernel.requestExecute({ code: demoSrc });
future.onIOPub = (msg) =>
msg.header.msg_type !== "status" && console.log(msg);
await future.done;
})();