#!/usr/bin/env python3 """Stable launcher for cece_capture_deep — logs exit code, avoids silent death.""" from __future__ import annotations import atexit import faulthandler import os import runpy import sys import time from pathlib import Path LOG = Path("/tmp/cece-capture-deep-full.log") FAULT = Path("/tmp/cece-fault.log") ROOT = Path("/Users/jack/Project/digital-psychology") def _log(msg: str) -> None: line = f"[{time.strftime('%F %T')}] {msg}\n" with LOG.open("a", encoding="utf-8") as f: f.write(line) sys.stdout.write(line) sys.stdout.flush() def main() -> int: os.chdir(ROOT) FAULT.parent.mkdir(parents=True, exist_ok=True) ff = FAULT.open("a", encoding="utf-8") faulthandler.enable(file=ff, all_threads=True) _log(f"launcher start pid={os.getpid()} argv={sys.argv[1:]}") def _atexit() -> None: _log(f"atexit pid={os.getpid()}") atexit.register(_atexit) sys.argv = ["cece_capture_deep.py", *sys.argv[1:]] try: runpy.run_path(str(ROOT / "tools" / "cece_capture_deep.py"), run_name="__main__") _log("launcher normal return") return 0 except BaseException as ex: _log(f"launcher exception: {type(ex).__name__}: {ex}") import traceback with LOG.open("a", encoding="utf-8") as f: traceback.print_exc(file=f) traceback.print_exc() return 1 if __name__ == "__main__": raise SystemExit(main())