Fix: import error

pyopenjtalk_worker.initialize() has the side effect of starting another process and should not be executed automatically on import.
This commit is contained in:
tsukumi
2024-03-08 07:31:33 +00:00
parent 75467936d9
commit 5de4884075
5 changed files with 16 additions and 15 deletions

View File

@@ -50,11 +50,11 @@ def unset_user_dict():
def initialize(port: int = WORKER_PORT) -> None:
import time
import socket
import sys
import atexit
import signal
import socket
import sys
import time
logger.debug("initialize")
global WORKER_CLIENT
@@ -83,7 +83,7 @@ def initialize(port: int = WORKER_PORT) -> None:
else:
# align with Windows behavior
# start_new_session is same as specifying setsid in preexec_fn
subprocess.Popen(args, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, start_new_session=True) # type: ignore
subprocess.Popen(args, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, start_new_session=True)
# wait until server listening
count = 0
@@ -92,10 +92,10 @@ def initialize(port: int = WORKER_PORT) -> None:
client = WorkerClient(port)
break
except socket.error:
time.sleep(1)
time.sleep(0.5)
count += 1
# 10: max number of retries
if count == 10:
# 20: max number of retries
if count == 20:
raise TimeoutError("サーバーに接続できませんでした")
WORKER_CLIENT = client