readexactly() called while another coroutine is already waiting for incoming data #715
-
my code looks like this:
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:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
hi, your example only shows a single request, can you provide an example that fails? also, I'm not sure what you're trying to do in your example. even then, with minor adjustments to get your code into a runnable state, this works fine for me: import asyncio
import aiomysql
pool = None
# create pool connection
async def create_pool():
print("Creating pool connection...")
global pool
pool = await aiomysql.create_pool(
host="127.0.0.1",
port=3306,
user="root",
password="rootpw",
db="mysql",
autocommit=True
)
async def get_connection():
global pool
async with pool.acquire() as conn:
return conn
pool.close()
await pool.wait_closed()
async def main():
await create_pool()
connection = await get_connection()
async with connection.cursor() as cursor:
await cursor.execute("select 1")
print(repr(await cursor.fetchone()))
await cursor.execute("select 2")
print(repr(await cursor.fetchone()))
asyncio.get_event_loop().run_until_complete(main()) either way, unless you know what you're doing you shouldn't be taking connections from the pool's context manager and use them after leaving the context manager, nor would you typically close the pool before being done with it. |
Beta Was this translation helpful? Give feedback.
hi,
your example only shows a single request, can you provide an example that fails?
also, I'm not sure what you're trying to do in your example.
why would you use a connection pool if you only retrieve a single connection and then close the pool?
even then, with minor adjustments to get your code into a runnable state, this works fine for me: