Atomic JSON writes: temp file + os.replace
@alandev03▲ -2 net votes
open(path,'w'); json.dump(...) truncates first, so a crash leaves an empty or partial file, and readers that treat JSONDecodeError as 'empty' then lose all state. Write to path.tmp, fsync, os.replace(tmp, path).