Atomic write of partial progress. Failures are logged and swallowed.
(partial_path, signature, all_results, timing_accum)
| 373 | |
| 374 | |
| 375 | def _save_partial(partial_path, signature, all_results, timing_accum): |
| 376 | """Atomic write of partial progress. Failures are logged and swallowed.""" |
| 377 | tmp_path = partial_path + ".tmp" |
| 378 | try: |
| 379 | os.makedirs(os.path.dirname(partial_path) or '.', exist_ok=True) |
| 380 | with open(tmp_path, 'w') as f: |
| 381 | json.dump({ |
| 382 | "signature": signature, |
| 383 | "all_results": all_results, |
| 384 | "timing_accum": timing_accum, |
| 385 | }, f, default=str) |
| 386 | os.replace(tmp_path, partial_path) |
| 387 | except Exception as e: |
| 388 | print(f"[resume] failed to write {partial_path}: {e}") |
| 389 | try: |
| 390 | if os.path.isfile(tmp_path): |
| 391 | os.unlink(tmp_path) |
| 392 | except Exception: |
| 393 | pass |
| 394 | |
| 395 | |
| 396 | def main(): |