代码点读机 / Python / await

await Python · 关键字

在 async 函数里等待一个可等待对象完成,等待期间不阻塞其他协程。

怎么用

await 可等待对象

小例子

import asyncio
async def 主():
    await asyncio.sleep(0)
    print('好了')
asyncio.run(主())

运行结果

好了

提醒:只能在 async def 函数内部使用。

官方文档:https://docs.python.org/zh-cn/3/reference/expressions.html#await

在代码里遇到不认识的词?打开代码点读机,点一下就懂 → ← Python全部词条