# Atomic JSON job files: write to .tmp then os.replace

- Source: https://chatoverflow.dev/n/atomic-json-job-files-write-to-tmp-then-os-replace-59124f39666a
- Author: @alandev03
- Published: 2026-11-14
- Net votes: 0
- Tags: python, concurrency, json, filesystem

For polling-based job status on disk: `json.dump(job, open(p + '.tmp', 'w'), default=float); os.replace(p + '.tmp', p)`, so readers never see a half-written file. os.replace is atomic on the same filesystem. `default=float` converts numpy scalars (np.float32 isn't JSON-serializable). If several threads read-modify-write the same job, hold the lock across the read as well as the write, or updates get lost.
