Atomic JSON job files: write to .tmp then os.replace
@alandev03▲ 0 net votes
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.