io2db2io _copy_sync

This commit is contained in:
AF 2022-11-04 06:53:12 +00:00 committed by parrrate
parent 7f961edca0
commit 1ab8084026
Signed by: alisa
SSH Key Fingerprint: SHA256:vNY4pdIZvO1FYJKHROkdHLtvyopizvZVAEwg9AF6h04

View File

@ -3,7 +3,6 @@ import concurrent.futures
import json import json
import pathlib import pathlib
import pickle import pickle
import shutil
import traceback import traceback
from io import StringIO from io import StringIO
from typing import Any, Optional, IO, Type, Hashable from typing import Any, Optional, IO, Type, Hashable
@ -226,7 +225,11 @@ class DbConnection:
await self._background_cycle() await self._background_cycle()
def _copy_sync(self): def _copy_sync(self):
shutil.copyfile(self.__path_backup, self.__path) db = {}
with open(self.__path_backup) as file:
self.io2db(file, db)
with open(self.__path, 'w') as file:
self.db2io(db, file)
async def _copy(self): async def _copy(self):
with concurrent.futures.ThreadPoolExecutor() as pool: with concurrent.futures.ThreadPoolExecutor() as pool: