Slow down the DB write interval and catch the case that it changed during write

pull/31/head
dgtlmoon 4 years ago
parent 6a78b5ad1d
commit b7efdfd52c

@ -247,8 +247,18 @@ class ChangeDetectionStore:
def sync_to_json(self): def sync_to_json(self):
print("Saving..") print("Saving..")
data ={}
try:
data = deepcopy(self.__data)
except RuntimeError:
time.sleep(0.5)
print ("! Data changed when writing to JSON, trying again..")
self.sync_to_json()
return
else:
with open(self.json_store_path, 'w') as json_file: with open(self.json_store_path, 'w') as json_file:
json.dump(self.__data, json_file, indent=4) json.dump(data, json_file, indent=4)
logging.info("Re-saved index") logging.info("Re-saved index")
self.needs_write = False self.needs_write = False
@ -263,6 +273,6 @@ class ChangeDetectionStore:
return return
if self.needs_write: if self.needs_write:
self.sync_to_json() self.sync_to_json()
time.sleep(1)
# body of the constructor time.sleep(3)

Loading…
Cancel
Save