Resolve #20: Na katex-server čekáme pomocí stdoutu.

This commit is contained in:
Jan Černohorský 2023-07-18 18:02:02 +02:00
parent 76c1a5fd04
commit 410c2852b2
2 changed files with 8 additions and 13 deletions

View file

@ -41,6 +41,7 @@ if (!unixSocketPath) {
// This server listens on a Unix socket at /var/run/mysocket
var unixServer = net.createServer(handleClient);
unixServer.listen(unixSocketPath);
console.log("OK")
function handleExit(signal) {
// unixServer.emit('close')

View file

@ -28,22 +28,16 @@ class KatexClient:
raise Exception("npm not found. Node.js is required to use KaTeX.")
else:
raise e
self._server_process = subprocess.Popen(["node", srcdir + "/katex-server/index.mjs", self._socket_file])
self._server_process = subprocess.Popen(["node", srcdir + "/katex-server/index.mjs", self._socket_file], stdout=subprocess.PIPE)
self._client = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
ok = self._server_process.stdout.readline()
if ok != b"OK\n":
raise Exception("Failed to connect to katex-server")
# Wait for the node program to create the socket file
while not os.path.exists(self._socket_file):
time.sleep(0.01)
# Wait for the node program to start accepting connections
while True:
try:
self._client.connect(self._socket_file)
time.sleep(0.01)
except ConnectionRefusedError:
continue
break
self._client.connect(self._socket_file)
def render(self, tex: str, options: Dict={}):
# Send formulas to translate