Closed stolenzc closed 1 year ago
I think you must close pool explicitly:
pool.close()
await pool.wait_closed()
or use context manager:
@asynccontextmanager
async def mysql_pool(loop):
config = {
"user": "user",
"password": "password",
"db": "database",
"port": 3306,
"host": "localhost",
"minsize": 1,
"maxsize": 5,
}
async with aiomysql.create_pool(**config, loop=loop) as pool:
yield pool
async def main(loop):
async with mysql_pool(loop) as pool:
...
Indeed, returning a connection to the pool does not close them.
The pool reuses connections as long as they're usable if pool_recycle
is not passed when creating the pool.
By specifying a timeout with pool_recycle
, the pool will eventually close old connections (lazily, next time a connection is acquired).
Describe the bug
I use this code running, you can see
conn._writer
is working after thewith
block, It meanspool.release
is not running as expected.The console output is as follows
To Reproduce
Reproduce like before code
Expected behavior
After
with
block,conn._writer
should beNone
Logs/tracebacks
Python Version
aiomysql Version
PyMySQL Version
SQLAlchemy Version
OS
Mac
Database type and version
Additional context
No response
Code of Conduct