def flush(self):
"""
Save storage contents to disk
This method saves new and changed :class:`Storage` contents to disk
and invalidates the Storage instance. Unchanged Storage is not saved
but simply invalidated.
"""
contents = pickle.dumps(self._storage)
if self._hash is None or md5(contents).hexdigest() != self._hash:
tmp = self._filename + '.tmp'
try:
with open(tmp, 'wb') as fo:
fo.write(contents)
except:
os.remove(tmp)
raise
move(tmp, self._filename) # Atomic save
del self._storage
评论列表
文章目录