code: def atomic_write(path, mode):
    
    tmp_path = "%s%s_%s" % (path, constants.INCOMPLETE_SUFFIX, uuid.uuid4().hex)
    with tf.io.gfile.GFile(tmp_path, mode) as file_:
      yield file_
    tf.io.gfile.rename(tmp_path, path, overwrite=True)
docs: Writes to path atomically, by writing to temp file and renaming it.