【发布时间】:2020-12-02 06:13:20
【问题描述】:
可以等待使用 'async' 关键字(Python 3.5+)创建的 Python 协程,但是,不能等待最外面的协程,因为 Python 说 “SyntaxError: 'await' outside function”
import asyncio as aio
async def f():
print(1)
await aio.sleep(3)
print(2)
return 3
print(await f())
如何“等待”上例中的“f”函数?
【问题讨论】:
标签: python promise async-await python-asyncio coroutine