File size: 1,603 Bytes
4ec41f2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python3
"""Launch the benchmark detached without placing API credentials in shell history."""
from __future__ import annotations

import getpass
import os
import subprocess
import sys
import time
from pathlib import Path


ROOT = Path(__file__).resolve().parents[1]
RUNNER = ROOT / "scripts/run_new_generation_benchmark.sh"
LOG_DIR = ROOT / "evaluation/new_generation100/logs"


def main() -> None:
    env = os.environ.copy()
    for name in ("STATEPLAY_GPT_API_KEY", "STATEPLAY_GEMINI_API_KEY"):
        if not env.get(name):
            if not sys.stdin.isatty():
                raise SystemExit(f"{name} is required; launch interactively or set it in the environment")
            env[name] = getpass.getpass(f"{name}: ").strip()
        if not env[name]:
            raise SystemExit(f"{name} cannot be empty")

    os.umask(0o077)
    LOG_DIR.mkdir(parents=True, exist_ok=True)
    log_path = LOG_DIR / "launcher.log"
    with log_path.open("ab") as log:
        process = subprocess.Popen(
            ["bash", str(RUNNER)],
            cwd=ROOT,
            env=env,
            stdin=subprocess.DEVNULL,
            stdout=log,
            stderr=subprocess.STDOUT,
            start_new_session=True,
        )
    (LOG_DIR / "launcher.pid").write_text(f"{process.pid}\n", encoding="ascii")
    del env
    time.sleep(2)
    if process.poll() is not None:
        raise SystemExit(f"Benchmark exited during startup (code {process.returncode}); see {log_path}")
    print(f"Started detached benchmark PID {process.pid}; log: {log_path}")


if __name__ == "__main__":
    main()