python - 什么时候输入 await ?在 python 中使用 aiohttp
问题描述
我使用 aiohttp 。我需要在应用程序的哪些地方输入 await ?据我所知,有以下情况:
当代码是关于会话时
async def get(self): session = await get_session(self.request)
当代码与数据库有关时
def __init__(self, db, **kwargs):
self.collection = db[MESSAGE_COLLECTION]
async def save(self, user, msg, **kw):
result = await self.collection.insert({'user': user, 'msg': msg, 'time': datetime.now()})
- 当代码与套接字有关时
async def get(self):
ws = web.WebSocketResponse()
await ws.prepare(self.request)
解决方案
推荐阅读
- powerbi - PowerBI--自定义列--Multiple Condition IF statements
- bash - bash 逐行同时循环遍历 2 个文件
- python - 如何使用字符串作为输入从 Matlab 调用 Matlab 函数
- excel - 为什么 Excel 内存不足?
- angular - Angular 6 ChartJS 动态创建画布并在其上创建图形 - 一个例子?
- amazon-ec2 - boto3如何从实例中检索弹性IP
- angular - 如何手动调用这些事件?ngOnInit 没有被使用组件工厂解析器注入的组件触发?
- sql - T-SQL - WHERE 子句查找输入日期在下周的位置,但也在当前季度
- android - 从 List 的第一个值中拉出
> 并在 TextView 上设置 - asp.net-mvc - 查询字符串参数名称与模型属性名称不同