version:
Python 3.6.9
aiomysql: 0.0.20
aiohttp: 3.6.2
问题:在mysql表中删除或插入数据,查询数据数小时不更新,除非web_app重启。
使用aiomysql池的代码:
# initial
pool = await aiomysql.create_pool(
# echo=True,
db=conf['database'],
user=conf['user'],
password=conf['password'],
host=conf['host'],
port=conf['port'],
minsize=conf['minsize'],
maxsize=conf['maxsize'],
)
# query
async def get_data(request)::
cmd = 'select a,b,c from tbl where d = 0'
# request.app['db'] == pool
async with request.app['db'].acquire() as conn:
async with conn.cursor() as cur:
await cur.execute(cmd)
...
当前解决方案:当aiomysql.create_pool似乎可以解决问题时,设置pool_recycle=20。为什么?还有更好的方法吗?
1条答案
按热度按时间hk8txs481#
我也有这个问题,并将
"autocommit": True
添加到我的db conf中为我修复了它。