File size: 1,727 Bytes
314ecfb | 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 52 53 54 55 56 57 58 59 | #!/usr/bin/env python3
"""Return 0 when all Bench2Drive worker checkpoints in a result root are finished."""
import argparse
import json
import sys
from pathlib import Path
def load_json(path: Path):
try:
with open(path, encoding="utf-8") as handle:
return json.load(handle)
except (OSError, json.JSONDecodeError):
return None
def main() -> int:
parser = argparse.ArgumentParser()
parser.add_argument("result_root", type=Path)
parser.add_argument(
"--workers",
type=int,
default=8,
help="Expected number of bench2drive220_worker_*.json files.",
)
args = parser.parse_args()
result_root = args.result_root.expanduser().resolve()
worker_files = sorted(result_root.glob("bench2drive220_worker_*.json"))
if len(worker_files) < args.workers:
print(
f"waiting: found {len(worker_files)}/{args.workers} worker checkpoints",
file=sys.stderr,
)
return 1
total_records = 0
for worker_file in worker_files:
data = load_json(worker_file)
if not isinstance(data, dict):
print(f"waiting: invalid checkpoint {worker_file.name}", file=sys.stderr)
return 1
if data.get("entry_status") != "Finished":
print(
f"waiting: {worker_file.name} entry_status={data.get('entry_status')}",
file=sys.stderr,
)
return 1
records = data.get("_checkpoint", {}).get("records", [])
total_records += len(records)
print(f"complete: {len(worker_files)} workers, {total_records} route records")
return 0
if __name__ == "__main__":
raise SystemExit(main())
|