python - 为什么我有时在使用 asyncio.run 时从未等待协程
问题描述
此错误很少见,但仍然存在。当同时发送两个或多个请求时会发生这种情况。
我尝试这样做:
adapter = OperatorCreator.create(
title=operator.slug,
api_key=operator.api_discount[0]
)
terminals = asyncio.run(
adapter.find_terminals(locality=locality), debug=True
)
return terminal
适配器:
async def find_terminals(self, locality: Locality, session: aiohttp.ClientSession = None) -> Mapping[str, Terminal]:
if 'dpd_terminals' in cache:
terminal_list = await sync_to_async(cache.get)('dpd_terminals')
else:
terminal_list = await self.add_terminals_from_request_to_cache()
terminals = terminal_list[str(locality.kladr)]
return terminals
然后有时我得到:
django_1 | /app/project/apps/geo/services.py:383:RuntimeWarning:从未等待协程“CdekAdapter.find_terminals”
django_1 | adapter.find_terminals(locality=locality)
django_1 | RuntimeWarning: 启用 tracemalloc 以获取对象分配回溯
我究竟做错了什么?
解决方案
推荐阅读
- contentful - 在从旧数据库迁移到 Contentful 时添加 sys 日期属性
- javascript - class sendAPICallback extends dAPIMessage { ^ TypeError: Class extends value undefined is not a constructor or null
- javascript - 有没有办法从通过 JavaScript 嵌入的 YouTube 视频中获取章节?
- html - 为什么在这种情况下隐藏的溢出不能像预期的那样工作?
- algorithm - UnionFind 与加权快速联合(又名按等级联合)
- javascript - 拒绝承诺时如何解决 UnhaldedPromiseRejectionWarning
- javascript - 移动菜单上导航链接上的动画错误
- sql - 为什么 PostgreSQL 索引在一段时间后停止使用
- reactjs - TypeError:cars.map 不是函数 - ReactJs
- asp.net-mvc - MVC 操作方法和 Web API 操作方法之间的区别