-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun_node.py
More file actions
29 lines (26 loc) · 868 Bytes
/
run_node.py
File metadata and controls
29 lines (26 loc) · 868 Bytes
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
import json, subprocess
__all__ = ["node_permute"]
# node_permute() runs the Node implementation using Node
def node_permute(score: dict[str, int],
magic: bytes=b'') -> list[str]:
# JSON doesn't understand bytes, but a small list of little ints
# works fine. Buffer.from() works on the other end to create Node's
# seemingly closest workalike to bytes.
args = {'magic': list(magic),
'score': score,
}
# Launch Node.js and feed JSON dict via stdin
try:
proc = subprocess.run(
["node", "permute_stdinout.js"],
input=json.dumps(args).encode(),
capture_output=True,
check=True,
)
except Exception as e:
print(e)
print(e.cmd)
print(e.output)
print(e.stderr)
raise
return json.loads(proc.stdout)