Hi! I am persisting data of my app in a plain json file (I know, very bare bones). I am having the issue that this file is not updated reliably. I'd say no content is written in 10% of trials. The method looks like this:
with open(self.data_file, "w+") as file:
file.write(self.data)
file.flush()
os.fsync(file.fileno())
file.close()
The flush() and fsync() I added after I first discovered the issue, however this did not help things.
The file is opened once the server starts up and the data kept in memory after that:
def __load_invoices(self):
if(os.path.exists(self.data_file)):
with open(self.data_file) as file:
self.invoices = json.load(
file, object_hook=InvoiceManager.date_hook)
file.close()
Any hint to what else I could do to have this file written properly?
Thanks!