任务已销毁,但未决错误

时间:2020-03-20 12:26:56

标签: postgresql python-3.6 python-asyncio asyncpg

我有一个名为engine.py的类,该类返回连接池。

class PIIEngine:

async def engine(self):
        self.pool = await asyncpg.create_pool(
          config.pg_gdpr_contact_db_url)

        return self.pool

然后我有另一个名为model.py的模块,

def get_contacts(id):
    async def get(loop):
        conn = await engine.engine()
        async with conn.acquire() as txn:
           async with txn.transaction():
              stmt = """
                SELECT *
                FROM
                    <TABLE>
                WHERE
                    id = $1
            """

              contact =  await txn.fetchrow(stmt, id)

              if contact:
                  return dict(contact)
              else:
                  return None
    loop = asyncio.new_event_loop()
    asyncio.set_event_loop(loop)
    asyncio.ensure_future(get(loop))
    loop.close()

函数get_contacts是从swagger api调用的,但是当我多次点击该api时,我会得到

ERROR    - asyncio - Task was destroyed but it is pending!
task: <Task pending coro=<get_contacts.<locals>.get() running at 
/usr/src/models.py:2>>

0 个答案:

没有答案