readexactly() called while another coroutine is already waiting for incoming data

1.2k Views Asked by At

Use pool connection - aiomysql

my code looks like this:

# POOL CONNECTION

# create pool connection
async def create_pool():
    print("Creating pool connection...")
    global pool

    pool = await aiomysql.create_pool(
        host=DB_HOST,
        port=DB_PORT,
        user=DB_USER,
        password=DB_PASSWORD,
        db=DB_DBNAME,
        autocommit=True
    )


async def get_connection():
    async with pool.acquire() as conn:
        return conn
    pool.close()
    await pool.wait_closed()


connection = await get_connection()
async with connection.cursor() as cursor:
            await cursor.execute(...)

If a single request is made, which makes the connection to mysql, it runs correctly, but if 2 or more requests are made at the same time, this crashes and thrown this error:

readexactly() called while another coroutine is already waiting for incoming data

0

There are 0 best solutions below