【问题标题】:Says 'coroutine was never awaited', but await exists in function说“从未等待过协程”,但函数中存在等待
【发布时间】:2022-07-19 21:35:01
【问题描述】:

我收到一条错误消息,提示我忘记等待一个协同程序,这是不正确的,如代码中突出显示的那样。

这是函数:

def _aio(self, f):
    """ Make some function run asynchronously. """

    async def aio_wrapper(**kwargs):
        f_bound = functools.partial(f, **kwargs)
        loop = asyncio.get_running_loop()
        return await loop.run_in_executor(self._executor, f_bound)

    return aio_wrapper

这是我使用的代码:

for key in image_keys:
    res = self._aio(self._client.get_object)(Bucket=self.bucket_name, Key=key)
    print(type(res))

【问题讨论】:

    标签: python python-asyncio


    【解决方案1】:

    你不awaitaio_wrapper

    res = await self._aio(self._client.get_object)(Bucket=self.bucket_name, Key=key)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-26
      • 1970-01-01
      • 1970-01-01
      • 2021-10-22
      • 2019-12-15
      相关资源
      最近更新 更多