save backups of brain files when saving

This commit is contained in:
Sniffleupagus
2023-05-19 11:01:08 -07:00
parent 4b89a3c8dd
commit d2c52e2673

View File

@ -81,6 +81,7 @@ class Stats(object):
with open(temp, 'wt') as fp: with open(temp, 'wt') as fp:
fp.write(data) fp.write(data)
if os.path.isfile(self.path):
os.replace(self.path, back) os.replace(self.path, back)
os.replace(temp, self.path) os.replace(temp, self.path)
@ -117,6 +118,7 @@ class AsyncTrainer(object):
temp = "%s.tmp" % self._nn_path temp = "%s.tmp" % self._nn_path
back = "%s.bak" % self._nn_path back = "%s.bak" % self._nn_path
self._model.save(temp) self._model.save(temp)
if os.path.isfile(self._nn_path):
os.replace(self._nn_path, back) os.replace(self._nn_path, back)
os.replace(temp, self._nn_path) os.replace(temp, self._nn_path)