pinokiod 3.2.147 → 3.2.149
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/kernel/python/index.js +50 -19
- package/package.json +1 -1
package/kernel/python/index.js
CHANGED
|
@@ -6,8 +6,40 @@ class Python {
|
|
|
6
6
|
}
|
|
7
7
|
async call(modname, modpath, method, args, ondata) {
|
|
8
8
|
console.log("CALL", { modname, modpath, method, args })
|
|
9
|
+
let res
|
|
10
|
+
for(let i=0; i<5; i++) {
|
|
11
|
+
console.log(`call attempt: ${i}`)
|
|
12
|
+
ondata({
|
|
13
|
+
raw: `\r\ncall attempt: ${i}\r\n`
|
|
14
|
+
})
|
|
15
|
+
res = await this._call(modname, modpath, method, args, ondata)
|
|
16
|
+
if (res) {
|
|
17
|
+
console.log("request successful")
|
|
18
|
+
ondata({
|
|
19
|
+
raw: "\r\nrequest successful\r\n"
|
|
20
|
+
})
|
|
21
|
+
break
|
|
22
|
+
} else {
|
|
23
|
+
console.log("request unsuccessful. retrying in 3 seconds...")
|
|
24
|
+
ondata({
|
|
25
|
+
raw: "\r\nrequest successful. retrying in 3 seconds...\r\n"
|
|
26
|
+
})
|
|
27
|
+
await new Promise((resolve, reject) => {
|
|
28
|
+
setTimeout(() => {
|
|
29
|
+
resolve()
|
|
30
|
+
}, 3000)
|
|
31
|
+
})
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return res
|
|
35
|
+
}
|
|
36
|
+
async _call(modname, modpath, method, args, ondata) {
|
|
9
37
|
// if this.proc doesn't exist, create
|
|
10
38
|
if (!this.proc) {
|
|
39
|
+
console.log("python rpc server not running. starting...")
|
|
40
|
+
ondata({
|
|
41
|
+
raw: "\r\npython rpc server not running. starting...\r\n"
|
|
42
|
+
})
|
|
11
43
|
await new Promise((resolve, reject) => {
|
|
12
44
|
this.kernel.exec({
|
|
13
45
|
message: "uvicorn --port 42001 server:app",
|
|
@@ -20,28 +52,27 @@ class Python {
|
|
|
20
52
|
}
|
|
21
53
|
})
|
|
22
54
|
})
|
|
23
|
-
console.log("Server Started")
|
|
24
|
-
await new Promise((resolve, reject) => {
|
|
25
|
-
setTimeout(() => {
|
|
26
|
-
resolve()
|
|
27
|
-
}, 3000)
|
|
28
|
-
})
|
|
29
55
|
}
|
|
30
56
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
57
|
+
try {
|
|
58
|
+
let res = await fetch("http://127.0.0.1:42001/call", {
|
|
59
|
+
method: "POST",
|
|
60
|
+
headers: { "Content-Type": "application/json" },
|
|
61
|
+
body: JSON.stringify({
|
|
62
|
+
name: modname,
|
|
63
|
+
path: modpath,
|
|
64
|
+
method,
|
|
65
|
+
params: args
|
|
66
|
+
})
|
|
67
|
+
}).then((res) => {
|
|
68
|
+
return res.json()
|
|
39
69
|
})
|
|
40
|
-
|
|
41
|
-
return res
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
|
|
70
|
+
this.proc = true
|
|
71
|
+
return res
|
|
72
|
+
} catch (e) {
|
|
73
|
+
console.log("FETCH ERROR", e)
|
|
74
|
+
this.proc = false
|
|
75
|
+
}
|
|
45
76
|
}
|
|
46
77
|
}
|
|
47
78
|
module.exports = Python
|