bench: a failed engine stop is loud and fails the run (#3438): stop_engine returns why the process may still be alive (taskkill result and exit, the 60 s and 30 s timeouts), the run prints an ERROR, writes ENGINE-NOT-STOPPED.txt, exits 6 and reports ok false
This commit is contained in:
1 parent
acf63bef73
commit
f8f4e8a7df
3 files changed
+125
-8
No files matched your search
@@ -684,13 +684,14 @@ def start_engine(ref: str, target: Target, log_path: Path, log, timeout_s: float
|
||||
proc._strata_log = handle # closed by stop_engine
|
||||
log("starting the engine (the model load is not part of the benchmark time) ...")
|
||||
if not _start_wait(target, proc, timeout_s, log, log_path):
|
||||
stop_engine(proc)
|
||||
stuck = stop_engine(proc)
|
||||
tail = ""
|
||||
try:
|
||||
tail = log_path.read_text(encoding="utf-8", errors="replace")[-600:]
|
||||
except OSError:
|
||||
pass
|
||||
raise ProfileError("the engine did not become ready" + (": " + tail.strip().splitlines()[-1] if tail.strip() else ""), 6)
|
||||
raise ProfileError("the engine did not become ready" + (": " + tail.strip().splitlines()[-1] if tail.strip() else "") +
|
||||
("; and it could not be stopped (" + stuck + "): it may still hold the port" if stuck else ""), 6)
|
||||
return proc
|
||||
|
||||
|
||||
@@ -712,14 +713,25 @@ def engine_log_since(console_log: Path, run_log: Path | None, offset: int) -> Pa
|
||||
return console_log
|
||||
|
||||
|
||||
def stop_engine(proc) -> None:
|
||||
"""Stop only the process this run started."""
|
||||
def stop_engine(proc) -> str | None:
|
||||
"""Stop only the process this run started. -> None when it is gone, else a plain sentence on why it may still be running
|
||||
(a failed taskkill / signal, or a process that outlives the wait): the caller must not report a normal finish then, because
|
||||
a process that is still alive can hold the server's port and the GPU (#3438)."""
|
||||
if proc is None:
|
||||
return
|
||||
return None
|
||||
problem = None
|
||||
try:
|
||||
if proc.poll() is None:
|
||||
if os.name == "nt":
|
||||
subprocess.run(["taskkill", "/PID", str(proc.pid), "/T", "/F"], capture_output=True, timeout=60)
|
||||
try:
|
||||
done = subprocess.run(["taskkill", "/PID", str(proc.pid), "/T", "/F"], capture_output=True, timeout=60)
|
||||
if done.returncode != 0 and proc.poll() is None:
|
||||
said = (done.stderr or done.stdout or b"").decode("utf-8", errors="replace").strip()
|
||||
problem = f"taskkill for process {proc.pid} failed (exit {done.returncode}){': ' + said[:200] if said else ''}"
|
||||
except subprocess.TimeoutExpired:
|
||||
problem = f"taskkill for process {proc.pid} did not finish in 60 s"
|
||||
except OSError as error:
|
||||
problem = f"taskkill could not run for process {proc.pid}: {error}"
|
||||
else:
|
||||
import signal
|
||||
try:
|
||||
@@ -737,10 +749,13 @@ def stop_engine(proc) -> None:
|
||||
proc.wait(30)
|
||||
except subprocess.TimeoutExpired:
|
||||
pass
|
||||
if proc.poll() is None:
|
||||
problem = (problem + "; " if problem else "") + f"process {proc.pid} is still running 30 s after it was told to stop"
|
||||
finally:
|
||||
handle = getattr(proc, "_strata_log", None)
|
||||
if handle is not None:
|
||||
handle.close()
|
||||
return problem
|
||||
|
||||
|
||||
def slug(text: str, limit: int = 40) -> str:
|
||||
|
||||
+13
-2
@@ -1282,6 +1282,7 @@ def _bench_standard(a: argparse.Namespace, machine: bool) -> int:
|
||||
import tempfile
|
||||
lease = benchmark_lease(saved["id"], out) if saved else contextlib.nullcontext()
|
||||
proc, scratch, engine_log, run_log, log_start = None, None, None, None, 0
|
||||
stop_problem = None
|
||||
try:
|
||||
with lease, contextlib.redirect_stdout(sys.stderr):
|
||||
def log(message: str) -> None:
|
||||
@@ -1301,13 +1302,23 @@ def _bench_standard(a: argparse.Namespace, machine: bool) -> int:
|
||||
engine_run_log=(run_log, log_start) if proc is not None else None,
|
||||
started_engine=proc is not None, hash_model=not a.skip_model_hash)
|
||||
finally:
|
||||
bench_standard.stop_engine(proc)
|
||||
stop_problem = bench_standard.stop_engine(proc)
|
||||
if not isinstance(stop_problem, str):
|
||||
stop_problem = None
|
||||
if scratch is not None:
|
||||
shutil.rmtree(scratch, ignore_errors=True)
|
||||
ok = doc["run"]["status"] == "complete"
|
||||
if stop_problem: # #3438: a stop that failed is not a normal finish: the engine may still hold the port and the GPU
|
||||
ok = False
|
||||
print(f"\nERROR: the engine this run started could not be stopped: {stop_problem}. It may still hold the server port "
|
||||
"and the GPU: stop it by hand before the next run. This run is marked FAILED.", file=sys.stderr, flush=True)
|
||||
try:
|
||||
(out_dir / "ENGINE-NOT-STOPPED.txt").write_text(stop_problem + "\n", encoding="utf-8")
|
||||
except OSError:
|
||||
pass
|
||||
path = out_dir / "results.json"
|
||||
if machine:
|
||||
print(json.dumps({"schema_version": 1, "ok": ok, "path": str(path.resolve()), "status": doc["run"]["status"],
|
||||
print(json.dumps({"schema_version": 1, "ok": ok, "path": str(path.resolve()), "status": "failed" if stop_problem else doc["run"]["status"], "engine_stop_error": stop_problem,
|
||||
"quality": doc["quality"], "summaries": doc["summaries"]}, ensure_ascii=False, allow_nan=False))
|
||||
else:
|
||||
print(bench_standard.format_plain(doc))
|
||||
|
||||
Reference in new issue
Block a user