win-ci: 조사 3 (Windows 변환 멈춤 단계별 확인), win_smoke 응답 없으면 워커 종료
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,18 +1,106 @@
|
||||
"""Windows 워커 크래시 원인 조사 2: winrt 가 자체 msvcp140.dll 을 먼저 올리면 onnxruntime/ctranslate2 가 죽는가."""
|
||||
import glob
|
||||
"""Windows 워커 변환 멈춤 원인 조사 3: 변환 단계를 하나씩 따로 돌려 어디서 멈추는지 본다.
|
||||
|
||||
각 경우를 자식 프로세스로 돌리고, 150초 안에 안 끝나면 faulthandler 로 모든 스레드의 스택을 찍고 죽인다.
|
||||
"""
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
sp = os.path.join(sys.prefix, "Lib", "site-packages")
|
||||
for f in glob.glob(os.path.join(sp, "**", "msvcp140*.dll"), recursive=True) + glob.glob(os.path.join(sp, "**", "vcruntime140*.dll"), recursive=True):
|
||||
v = subprocess.run(["powershell", "-NoProfile", "-Command", f"(Get-Item '{f}').VersionInfo.FileVersion"], capture_output=True, text=True).stdout.strip()
|
||||
print("bundled", f.replace(sp, "site-packages"), v, flush=True)
|
||||
for code in [
|
||||
"import winrt.windows.media.ocr; import onnxruntime; print('winrt then ort ok')",
|
||||
"import winrt.windows.media.ocr; import ctranslate2; print('winrt then ct2 ok')",
|
||||
"import onnxruntime, ctranslate2; import winrt.windows.media.ocr; print('ort,ct2 then winrt ok')",
|
||||
"import gvr_worker.ocr as o; import onnxruntime; print('gvr ocr then ort ok')",
|
||||
]:
|
||||
p = subprocess.run([sys.executable, "-X", "faulthandler", "-c", code], capture_output=True, text=True, encoding="utf-8", errors="replace", timeout=300, cwd=os.path.join(os.path.dirname(__file__), ".."))
|
||||
print(f"--- {code} -> exit {p.returncode} (0x{p.returncode & 0xffffffff:08X})", p.stdout.strip()[-200:], p.stderr.strip()[-600:], flush=True)
|
||||
HERE = os.path.dirname(os.path.abspath(__file__))
|
||||
WORKER = os.path.dirname(HERE)
|
||||
OGG = os.path.join(WORKER, "..", "app", "resources", "diag", "speech_ko.ogg").replace("\\", "/")
|
||||
|
||||
PRE = (
|
||||
"import faulthandler, sys, time\n"
|
||||
"faulthandler.dump_traceback_later(150, exit=True)\n"
|
||||
"T=time.time()\n"
|
||||
"def p(m): print(f'{time.time()-T:6.1f}s {m}', flush=True)\n"
|
||||
)
|
||||
STEPS = (
|
||||
f"from gvr_worker import audio as A\n"
|
||||
f"prep = A.prepare('{OGG}', target_lufs=-18.0, profile_lufs=None, use_denoise=False); p(f'prepare ok {{prep.duration_s}}s')\n"
|
||||
"from gvr_worker.stt import _vad_speech\n"
|
||||
"p(f'vad {_vad_speech(prep.audio)}')\n"
|
||||
"from faster_whisper import WhisperModel\n"
|
||||
"m = WhisperModel('tiny', device='cpu', compute_type='int8', cpu_threads=CT); p('load ok')\n"
|
||||
"segs, _ = m.transcribe(prep.audio, language='ko', beam_size=1, vad_filter=VF, word_timestamps=WT); p('generator')\n"
|
||||
"p('text ' + ''.join(s.text for s in segs))\n"
|
||||
)
|
||||
CASES = {
|
||||
"plain": "CT=0; VF=False; WT=False\n",
|
||||
"vadfilter": "CT=0; VF=True; WT=False\n",
|
||||
"words": "CT=0; VF=False; WT=True\n",
|
||||
"full": "CT=0; VF=True; WT=True\n",
|
||||
"full_1thread": "CT=1; VF=True; WT=True\n",
|
||||
"preload_full": "import onnxruntime, ctranslate2; p('preloaded')\nCT=0; VF=True; WT=True\n",
|
||||
"ct2_first_full": "import ctranslate2; p('ct2 loaded')\nCT=0; VF=True; WT=True\n",
|
||||
}
|
||||
env = {**os.environ, "PYTHONUTF8": "1", "PYTHONIOENCODING": "utf-8"}
|
||||
for name, head in CASES.items():
|
||||
code = PRE + head + STEPS
|
||||
try:
|
||||
p = subprocess.run([sys.executable, "-c", code], capture_output=True, text=True, encoding="utf-8",
|
||||
errors="replace", timeout=240, cwd=WORKER, env=env)
|
||||
rc = f"{p.returncode} (0x{p.returncode & 0xffffffff:08X})"
|
||||
out, err = p.stdout, p.stderr
|
||||
except subprocess.TimeoutExpired as e:
|
||||
rc, out, err = "TIMEOUT", str(e.stdout or ""), str(e.stderr or "")
|
||||
print(f"===== {name} -> exit {rc}", flush=True)
|
||||
print(out.strip()[-1500:], flush=True)
|
||||
if err.strip():
|
||||
print("--- stderr", flush=True)
|
||||
print(err.strip()[-3500:], flush=True)
|
||||
|
||||
# 실제 워커 프로토콜 그대로 (pytest·win_smoke 와 같은 경로). 멈추면 200초 뒤 모든 스레드 스택을 파일로 남긴다.
|
||||
import json
|
||||
import queue
|
||||
import tempfile
|
||||
import threading
|
||||
|
||||
data = tempfile.mkdtemp(prefix="gvr-dbg-")
|
||||
dump = os.path.join(data, "stack.txt")
|
||||
boot = ("import faulthandler, os, runpy, sys\n"
|
||||
"f = open(os.environ['GVR_DUMP'], 'w')\n"
|
||||
"faulthandler.dump_traceback_later(200, exit=True, file=f)\n"
|
||||
"sys.argv = ['gvr_worker']\n"
|
||||
"runpy.run_module('gvr_worker', run_name='__main__')\n")
|
||||
wp = subprocess.Popen([sys.executable, "-c", boot], cwd=WORKER, env={**env, "GVR_DATA_DIR": data, "GVR_DUMP": dump},
|
||||
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, encoding="utf-8")
|
||||
q: "queue.Queue[str]" = queue.Queue()
|
||||
errs: list = []
|
||||
threading.Thread(target=lambda: [q.put(l) for l in wp.stdout], daemon=True).start()
|
||||
threading.Thread(target=lambda: [errs.append(l.rstrip()) for l in wp.stderr], daemon=True).start()
|
||||
|
||||
|
||||
def req(rid, op, timeout, **kw):
|
||||
wp.stdin.write(json.dumps({"id": rid, "op": op, **kw}, ensure_ascii=False) + "\n")
|
||||
wp.stdin.flush()
|
||||
while True:
|
||||
line = q.get(timeout=timeout)
|
||||
msg = json.loads(line)
|
||||
if msg.get("id") == rid and "event" not in msg:
|
||||
return msg
|
||||
|
||||
|
||||
print("===== protocol", flush=True)
|
||||
try:
|
||||
for rid, op, to, kw in [
|
||||
("1", "download", 900, {"target": "model", "name": "tiny"}),
|
||||
("2", "load", 300, {"slot": "realtime", "model": "tiny", "device": "cpu", "compute_type": "int8"}),
|
||||
("3", "transcribe", 260, {"slot": "realtime", "path": OGG, "hotwords": "", "corrections": [], "dictionary": [],
|
||||
"target_lufs": -18, "noise_sensitivity": 0.5, "denoise": False, "profile_lufs": None}),
|
||||
]:
|
||||
r = req(rid, op, to, **kw)
|
||||
print(op, json.dumps(r, ensure_ascii=False)[:400], flush=True)
|
||||
except queue.Empty:
|
||||
print("응답 없음 (멈춤)", flush=True)
|
||||
wp.stdin.close()
|
||||
try:
|
||||
wp.wait(timeout=30)
|
||||
except subprocess.TimeoutExpired:
|
||||
wp.kill()
|
||||
wp.wait()
|
||||
print("worker exit", wp.returncode, flush=True)
|
||||
print("--- stderr tail\n" + "\n".join(errs[-30:]), flush=True)
|
||||
if os.path.exists(dump):
|
||||
print("--- stack dump\n" + open(dump, encoding="utf-8", errors="replace").read()[-6000:], flush=True)
|
||||
|
||||
@@ -9,6 +9,7 @@ from __future__ import annotations
|
||||
import argparse
|
||||
import json
|
||||
import os
|
||||
import queue
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
@@ -27,7 +28,15 @@ class Worker:
|
||||
env=env, cwd=str(ROOT / "worker"), text=True, encoding="utf-8", bufsize=1)
|
||||
self.seq = 0
|
||||
self.err: list[str] = []
|
||||
self.out: "queue.Queue[str | None]" = queue.Queue()
|
||||
threading.Thread(target=self._drain, daemon=True).start()
|
||||
threading.Thread(target=self._read, daemon=True).start()
|
||||
|
||||
def _read(self) -> None:
|
||||
assert self.p.stdout
|
||||
for line in self.p.stdout:
|
||||
self.out.put(line)
|
||||
self.out.put(None)
|
||||
|
||||
def _drain(self) -> None:
|
||||
assert self.p.stderr
|
||||
@@ -40,15 +49,19 @@ class Worker:
|
||||
assert self.p.stdin and self.p.stdout
|
||||
self.p.stdin.write(json.dumps({"id": rid, "op": op, **kw}, ensure_ascii=False) + "\n")
|
||||
self.p.stdin.flush()
|
||||
t0 = time.time()
|
||||
while time.time() - t0 < timeout:
|
||||
line = self.p.stdout.readline()
|
||||
if not line:
|
||||
deadline = time.time() + timeout
|
||||
while True:
|
||||
try:
|
||||
line = self.out.get(timeout=max(deadline - time.time(), 0.1))
|
||||
except queue.Empty:
|
||||
# 워커가 멈춘 경우: 무한 대기하지 않고 죽인 뒤 실패로 끝낸다
|
||||
self.p.kill()
|
||||
raise TimeoutError(f"{op} {timeout}s 응답 없음: " + "\n".join(self.err[-20:])) from None
|
||||
if line is None:
|
||||
raise RuntimeError("worker exited: " + "\n".join(self.err[-20:]))
|
||||
msg = json.loads(line)
|
||||
if msg.get("id") == rid and "event" not in msg:
|
||||
return msg
|
||||
raise TimeoutError(op)
|
||||
|
||||
|
||||
def main() -> int:
|
||||
|
||||
Reference in New Issue
Block a user