This commit is contained in:
AF 2022-11-04 06:12:35 +00:00
parent d1564637f2
commit 80aa527e52
8 changed files with 11 additions and 62 deletions

8
.idea/.gitignore vendored
View File

@ -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/

View File

@ -1,20 +0,0 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="DuplicatedCode" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
<inspection_tool class="PyPackageRequirementsInspection" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ignoredPackages">
<value>
<list size="1">
<item index="0" class="java.lang.String" itemvalue="nacl" />
</list>
</value>
</option>
</inspection_tool>
<inspection_tool class="SpellCheckingInspection" enabled="false" level="TYPO" enabled_by_default="false">
<option name="processCode" value="true" />
<option name="processLiterals" value="true" />
<option name="processComments" value="true" />
</inspection_tool>
</profile>
</component>

View File

@ -1,4 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (ptvp35)" project-jdk-type="Python SDK" />
</project>

View File

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/ptvp35.iml" filepath="$PROJECT_DIR$/.idea/ptvp35.iml" />
</modules>
</component>
</project>

View File

@ -1,10 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/venv" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@ -1,4 +1,5 @@
import asyncio import asyncio
import concurrent.futures
import json import json
import pathlib import pathlib
import pickle import pickle
@ -101,6 +102,7 @@ class TransactionRequest(Request):
class DbConnection: class DbConnection:
__mmdb: dict __mmdb: dict
__loop: asyncio.AbstractEventLoop __loop: asyncio.AbstractEventLoop
__pool: concurrent.futures.Executor
__queue: asyncio.Queue[Request] __queue: asyncio.Queue[Request]
__file: IO[str] __file: IO[str]
__buffer: StringIO __buffer: StringIO
@ -179,7 +181,7 @@ class DbConnection:
async def _dump_compressed_buffer(self): async def _dump_compressed_buffer(self):
buffer = self._compress_buffer() 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): async def _do_dump_buffer(self):
await self._dump_compressed_buffer() await self._dump_compressed_buffer()
@ -196,7 +198,7 @@ class DbConnection:
async def _save_error(self, line: str): async def _save_error(self, line: str):
with open(self.__path_error, 'a') as file: 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): async def _handle_request(self, request: Request):
if isinstance(request, self.factory.kvrequest_type): if isinstance(request, self.factory.kvrequest_type):
@ -225,13 +227,13 @@ class DbConnection:
await self._background_cycle() await self._background_cycle()
async def _finish_recovery(self): 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_recover.unlink()
self.__path_backup.unlink() self.__path_backup.unlink()
async def _build_file(self, db: dict): async def _build_file(self, db: dict):
with open(self.__path_backup, "w") as file: 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() self.__path_recover.touch()
await self._finish_recovery() await self._finish_recovery()
@ -240,7 +242,7 @@ class DbConnection:
await self._finish_recovery() await self._finish_recovery()
self.__path.touch() self.__path.touch()
with open(self.__path) as file: 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) await self._build_file(db)
async def _reload(self): async def _reload(self):
@ -266,6 +268,7 @@ class DbConnection:
async def _initialize(self): async def _initialize(self):
assert self.not_running assert self.not_running
self.__loop = asyncio.get_event_loop() self.__loop = asyncio.get_event_loop()
self.__pool = concurrent.futures.ThreadPoolExecutor()
await self._initialize_queue() await self._initialize_queue()
await self._initialize_mmdb() await self._initialize_mmdb()
await self._start_task() await self._start_task()
@ -285,8 +288,10 @@ class DbConnection:
self.__file.close() self.__file.close()
await self._build_file(self.__mmdb) await self._build_file(self.__mmdb)
self.not_running = True self.not_running = True
self.__pool.shutdown()
del self.__mmdb del self.__mmdb
del self.__loop del self.__loop
del self.__pool
del self.__queue del self.__queue
del self.__file del self.__file
del self.__buffer del self.__buffer

View File

@ -6,7 +6,7 @@ setup(
packages=['ptvp35'], packages=['ptvp35'],
url='https://gitea.ongoteam.net/PTV/ptvp35', url='https://gitea.ongoteam.net/PTV/ptvp35',
license='', license='',
author='PARRRATE T&V', author='PARRRATE TNV',
author_email='', author_email='',
description='' description=''
) )