#!/usr/bin/env python3 """Reproduce Joblib loky spawnv_passfds process execution.""" from __future__ import annotations import argparse import json import os import shutil import subprocess import sys import tempfile from pathlib import Path MARKER = "mfv_loky_spawnv_passfds_marker.txt" def run_one(artifact: Path) -> dict: work_root = Path(tempfile.mkdtemp(prefix="joblib_spawnv_repro_")) local_artifact = work_root / artifact.name shutil.copy2(artifact, local_artifact) proc = subprocess.run( [ sys.executable, "-c", ( "import joblib, os; " f"pid=joblib.load({str(local_artifact)!r}); " "print(repr(pid)); " "os.waitpid(pid, 0) if isinstance(pid, int) and pid > 0 else None" ), ], cwd=str(work_root), capture_output=True, text=True, check=False, timeout=10, ) marker = work_root / MARKER result = { "artifact": artifact.name, "returncode": proc.returncode, "stdout": proc.stdout.strip(), "stderr_tail": proc.stderr[-1000:], "marker_exists": marker.exists(), "marker_text": marker.read_text() if marker.exists() else None, "files": sorted(p.name for p in work_root.iterdir()), } shutil.rmtree(work_root, ignore_errors=True) return result def main() -> None: ap = argparse.ArgumentParser() ap.add_argument("artifacts", nargs="+", type=Path) args = ap.parse_args() print(json.dumps([run_one(path) for path in args.artifacts], indent=2)) if __name__ == "__main__": main()