ACG Projects
File /machine-took-my-shift/work/queue_lowres_v2_after_v1.py
queue_lowres_v2_after_v1.py
Download Open raw
from __future__ import annotations

import argparse
import shutil
import subprocess
import sys
import time
from pathlib import Path


def _repo_root() -> Path:
    return Path(__file__).resolve().parents[3]


def _any_process_matches(pattern: str) -> bool:
    pgrep = shutil.which("pgrep")
    if pgrep:
        r = subprocess.run([pgrep, "-f", pattern], capture_output=True, text=True)
        return r.returncode == 0 and (r.stdout or "").strip() != ""

    # Fallback if pgrep is unavailable.
    r = subprocess.run(["ps", "aux"], capture_output=True, text=True, check=False)
    return pattern in (r.stdout or "")


def main() -> int:
    parser = argparse.ArgumentParser(
        description="Wait for lowres v1 generation to finish, then launch v2 in a new console."
    )
    parser.add_argument("--interval", type=float, default=10.0, help="Polling interval (seconds).")
    parser.add_argument(
        "--pattern",
        default="projects/machine-took-my-shift/work/generate_images_lowres.py",
        help="Process match pattern to wait for (pgrep -f).",
    )
    args = parser.parse_args()

    root = _repo_root()
    run_in_console = Path("/home/Marcel/.codex/skills/run-in-console/scripts/run_in_console.sh")
    if not run_in_console.exists():
        raise SystemExit(f"Missing launcher: {run_in_console}")

    v2_prompts = "projects/machine-took-my-shift/work/prompts/lowres_v2_story.yaml"
    v2_outdir = "projects/machine-took-my-shift/work/images/lowres_v2"

    print(f"Watching for running process matching: {args.pattern}")
    while _any_process_matches(args.pattern):
        print("Still running… waiting.")
        time.sleep(max(1.0, args.interval))

    print("v1 appears done. Launching v2 in a new console…")
    cmd = [
        "bash",
        str(run_in_console),
        "--title",
        "SimpleGen: machine-took-my-shift (v2 story, 30 lowres)",
        "--cwd",
        str(root),
        "--hold",
        "--",
        "python",
        "projects/machine-took-my-shift/work/generate_images_lowres.py",
        "--prompts",
        v2_prompts,
        "--outdir",
        v2_outdir,
    ]
    subprocess.run(cmd, check=True)
    print("Launched v2 console.")
    return 0


if __name__ == "__main__":
    raise SystemExit(main())

Paste