2
version: 
    Python 3.6.9
    aiomysql: 0.0.20
    aiohttp: 3.6.2

problem: where mysql table data deleted or inserted, query data is not updated for hours, unless web_app restart.

codes using aiomysql pool:

  # 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)
                  ...

current solution: set pool_recycle=20 when aiomysql.create_pool seems solve the problem. but why? other better way?

whi
  • 2,685
  • 6
  • 33
  • 40
  • You cannot await inside a function that is not async. Make it `async def get_data():` and call it accordingly, i.e. with `loop.run_until_complete` or `asyncio.run` – Pynchia Aug 28 '20 at 04:18
  • sure, i forgot write exact the defintion – whi Aug 28 '20 at 05:48

1 Answers1

0

I was having this issue as well and adding "autocommit": True into my db conf fixed it for me.

    pool = await aiomysql.create_pool(
        host=...,
        user=...,
        password=...,
        db=...,
        port=...,
        # etc
        autocommit=True,
        loop=asyncio.get_running_loop())
Mike
  • 70
  • 6