diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 73f69e0..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Datasource local storage ignored files -/dataSources/ -/dataSources.local.xml -# Editor-based HTTP Client requests -/httpRequests/ diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml deleted file mode 100644 index d25344e..0000000 --- a/.idea/inspectionProfiles/Project_Default.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 21c84a0..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 20fe4ca..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/ptvp35.iml b/.idea/ptvp35.iml deleted file mode 100644 index 74d515a..0000000 --- a/.idea/ptvp35.iml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/ptvp35/__init__.py b/ptvp35/__init__.py index 01ee527..364b6e2 100644 --- a/ptvp35/__init__.py +++ b/ptvp35/__init__.py @@ -1,4 +1,5 @@ import asyncio +import concurrent.futures import json import pathlib import pickle @@ -101,6 +102,7 @@ class TransactionRequest(Request): class DbConnection: __mmdb: dict __loop: asyncio.AbstractEventLoop + __pool: concurrent.futures.Executor __queue: asyncio.Queue[Request] __file: IO[str] __buffer: StringIO @@ -179,7 +181,7 @@ class DbConnection: 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(self.__pool, self.__file.write, buffer.getvalue()) async def _do_dump_buffer(self): await self._dump_compressed_buffer() @@ -196,7 +198,7 @@ class DbConnection: async def _save_error(self, line: str): with open(self.__path_error, 'a') as file: - await self.__loop.run_in_executor(None, file.write, line.strip() + '\n') + await self.__loop.run_in_executor(self.__pool, file.write, line.strip() + '\n') async def _handle_request(self, request: Request): if isinstance(request, self.factory.kvrequest_type): @@ -225,13 +227,13 @@ class DbConnection: await self._background_cycle() async def _finish_recovery(self): - await self.__loop.run_in_executor(None, shutil.copy, self.__path_backup, self.__path) + await self.__loop.run_in_executor(self.__pool, shutil.copy, self.__path_backup, self.__path) self.__path_recover.unlink() self.__path_backup.unlink() async def _build_file(self, db: dict): with open(self.__path_backup, "w") as file: - self.__initial_size = await self.__loop.run_in_executor(None, self.db2io, db, file) + self.__initial_size = await self.__loop.run_in_executor(self.__pool, self.db2io, db, file) self.__path_recover.touch() await self._finish_recovery() @@ -240,7 +242,7 @@ class DbConnection: await self._finish_recovery() self.__path.touch() with open(self.__path) as file: - await self.__loop.run_in_executor(None, self.io2db, file, db) + await self.__loop.run_in_executor(self.__pool, self.io2db, file, db) await self._build_file(db) async def _reload(self): @@ -266,6 +268,7 @@ class DbConnection: async def _initialize(self): assert self.not_running self.__loop = asyncio.get_event_loop() + self.__pool = concurrent.futures.ThreadPoolExecutor() await self._initialize_queue() await self._initialize_mmdb() await self._start_task() @@ -285,8 +288,10 @@ class DbConnection: self.__file.close() await self._build_file(self.__mmdb) self.not_running = True + self.__pool.shutdown() del self.__mmdb del self.__loop + del self.__pool del self.__queue del self.__file del self.__buffer diff --git a/setup.py b/setup.py index 2b1a7c0..863c09c 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ setup( packages=['ptvp35'], url='https://gitea.ongoteam.net/PTV/ptvp35', license='', - author='PARRRATE T&V', + author='PARRRATE TNV', author_email='', description='' )