Невозможно получить соединение после закрытия пулаPython

Программы на Python
Anonymous
Невозможно получить соединение после закрытия пула

Сообщение Anonymous »

Когда я вызываю функции, возникает ошибка
RuntimeError: невозможно получить соединение после закрытия пула
но я нигде не закрываю пул
from aiomysql import create_pool, Cursor
import asyncio
from env import DATABASE, HOST, PORT, USER, PASSWORD

class Table:
def __init__(self) -> None:
l = asyncio.get_event_loop()
self.pool = l.run_until_complete(create_pool(
host=HOST,
port=PORT,
user=USER,
password=PASSWORD,
db=DATABASE,
cursorclass=Cursor,
autocommit=True,
loop = asyncio.get_event_loop(),
maxsize=15
))

async def f(self):
async with self.pool as pool:
async with pool.acquire() as conn:
async with conn.cursor() as cursor:
QUERY = f"""SELECT 1;"""
await cursor.execute(QUERY, (user_id))
return (await cursor.fetchone())[0]


Подробнее здесь: https://stackoverflow.com/questions/787 ... osing-pool

Вернуться в «Python»