При быстрых, постоянных запросах получаю ошибку
RuntimeError: read() called while another coroutine is already waiting for incoming data
await self.cursor.execute(*args)
q = await self.cursor.fetchone()
Подключение к базе данных
async def register_base(host, port, user, password, db):
db = await connect(user=user, password=password, host=host, port=port, database=db, use_pure=True)
cursor = await db.cursor()
return db, cursor
class Base():
def __init__(self, host, port, user, password, db, run_func=None):
loop = asyncio.get_event_loop()
self.db, self.cursor = loop.run_until_complete(register_base(host, port, user, password, db))
if run_func is not None: loop.run_until_complete(run_func(self))
async def __get_dict_from_request(self, *args, q):
args = str(args[0])
s = {}
splits = args.split('SELECT')[1].split('FROM')[0].split(',')
for c in range(len(splits)):
j = splits[c].replace(' ', '').replace(".", "_").replace('`', '')
if len(j.split('(')) >= 2: j = j.split('(')[1].replace(')', '')
s[j] = q[c]
return s
async def fetchone(self, *args, dict=False):
await self.cursor.execute(*args)
q = await self.cursor.fetchone()
if dict is True and q is not None:
s = await self.__get_dict_from_request(*args, q=q)
return s
return q
async def fetchall(self, *args, dict=False):
await self.cursor.execute(*args)
q = await self.cursor.fetchall()
if dict is True:
s = []
for j in q:
s_ = await self.__get_dict_from_request(*args, q=j)
s.append(s_)
return s
return q
async def execute(self, *args):
await self.cursor.execute(*args)
return True
async def commit(self):
await self.conn.commit()
return True