1
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。但为什么?其他更好的方法?

4

0 回答 0