flush + fsync

This commit is contained in:
AF 2022-11-08 15:01:45 +00:00 committed by parrrate
parent 9e7be91dd7
commit 30f44a82ef
Signed by: alisa
SSH Key Fingerprint: SHA256:vNY4pdIZvO1FYJKHROkdHLtvyopizvZVAEwg9AF6h04

View File

@ -1,5 +1,6 @@
import asyncio
import json
import os
import pathlib
import pickle
import threading
@ -177,9 +178,14 @@ class DbConnection:
self.db2io(bufferdb, buffer)
return buffer
def _file_write(self, line: str):
self.__file.write(line)
self.__file.flush()
os.fsync(self.__file.fileno())
async def _dump_compressed_buffer(self):
buffer = self._compress_buffer()
await self.__loop.run_in_executor(None, self.__file.write, buffer.getvalue())
await self.__loop.run_in_executor(None, self._file_write, buffer.getvalue())
async def _do_dump_buffer(self):
await self._dump_compressed_buffer()