Update.
This commit is contained in:
parent
634aa535de
commit
5c6d837f10
@ -10,10 +10,11 @@ class BaseMapper:
|
||||
model_class: BaseModel = None
|
||||
default_limit: int = DEFAULT_LIMIT
|
||||
table_name: str = None
|
||||
|
||||
semaphore = asyncio.Semaphore(1)
|
||||
|
||||
def __init__(self, app):
|
||||
self.app = app
|
||||
self.semaphore = asyncio.Semaphore(1)
|
||||
|
||||
self.default_limit = self.__class__.default_limit
|
||||
|
||||
@property
|
||||
@ -26,19 +27,16 @@ class BaseMapper:
|
||||
|
||||
async def run_in_executor(self, func, *args, **kwargs):
|
||||
use_semaphore = kwargs.pop("use_semaphore", False)
|
||||
if use_semaphore:
|
||||
async with self.semaphore:
|
||||
database_exception = None
|
||||
for x in range(20):
|
||||
try:
|
||||
result = func(*args, **kwargs)
|
||||
self.db.commit()
|
||||
return result
|
||||
except Exception as ex:
|
||||
await asyncio.sleep(0)
|
||||
database_exception = ex
|
||||
raise database_exception
|
||||
return await self.loop.run_in_executor(None, lambda: func(*args, **kwargs))
|
||||
|
||||
def _execute():
|
||||
result = func(*args, **kwargs)
|
||||
if use_semaphore:
|
||||
self.db.commit()
|
||||
return result
|
||||
|
||||
async with self.semaphore:
|
||||
return await self.loop.run_in_executor(None, _execute)
|
||||
|
||||
|
||||
async def new(self):
|
||||
return self.model_class(mapper=self, app=self.app)
|
||||
|
@ -32,7 +32,7 @@
|
||||
{% endfor %}
|
||||
<div class="message-list-bottom"></div>
|
||||
</message-list>
|
||||
<chat-input live-type="false" channel="{{ channel.uid.value }}"></chat-input>
|
||||
<chat-input live-type="true" channel="{{ channel.uid.value }}"></chat-input>
|
||||
</section>
|
||||
{% include "dialog_container.html" %}
|
||||
{% include "dialog_help.html" %}
|
||||
|
Loading…
Reference in New Issue
Block a user