Skip to content

Commit

Permalink
flush data when performing backup for persistent dict
Browse files Browse the repository at this point in the history
  • Loading branch information
rodja committed Feb 7, 2025
1 parent 5b42401 commit 0f244d0
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions nicegui/persistence/file_persistent_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@ def backup(self) -> None:
self.filepath.parent.mkdir(exist_ok=True)

async def backup() -> None:
async with aiofiles.open(self.filepath, 'w', encoding=self.encoding) as f:
await f.write(json.dumps(self, indent=self.indent))
try:
async with aiofiles.open(self.filepath, 'w', encoding=self.encoding) as f:
await f.write(json.dumps(self, indent=self.indent))
await f.flush()
except Exception:
log.exception('Error during file persistence backup')
if core.loop:
background_tasks.create_lazy(backup(), name=self.filepath.stem)
else:
Expand Down

0 comments on commit 0f244d0

Please sign in to comment.