testspace / space_app /flow_free_runner.py
Mayug Maniparambil
Isolate flow_free verification in a timeout-bounded subprocess
30865cf
Raw
History Blame Contribute Delete
1 kB
"""Standalone runner for flow_free verification.
Invoked as a subprocess by VerificationService so that the FlowFree solver
(which compiles/runs a native binary, has no internal timeout, and can raise
SystemExit on a missing compiler/binary) cannot hang or crash the web worker.
Reads a JSON object {"problem_ascii": ..., "board_ascii": ...} on stdin and
writes the verification result dict as JSON to stdout.
"""
from __future__ import annotations
import json
import sys
from pathlib import Path
ROOT_DIR = Path(__file__).resolve().parents[1]
EVALS_SRC_DIR = ROOT_DIR / "evals" / "src"
if str(EVALS_SRC_DIR) not in sys.path:
sys.path.insert(0, str(EVALS_SRC_DIR))
def main() -> None:
payload = json.loads(sys.stdin.read())
from evals_verifier import verify_flow_free # type: ignore
result = verify_flow_free(
payload.get("problem_ascii", ""),
payload.get("board_ascii", ""),
)
sys.stdout.write(json.dumps(result))
if __name__ == "__main__":
main()