小编sha*_*aka的帖子

从异步函数调用普通函数与从异步函数调用协程有什么区别?

  1. async def caller():
        await bar()
        print("finish")
    
    async def bar():
       // some code here
    
    Run Code Online (Sandbox Code Playgroud)
  2. async def caller():
        bar()
        print("finish")
    
    def bar():
       //some code here
    
    Run Code Online (Sandbox Code Playgroud)

在上面的例子中。两种情况下,调用者都必须等待 bar() 完成。在这种情况下,bar 成为普通/协程有什么不同吗?如果我们想“等待”某些函数,为什么不使用普通函数。

python async-await python-asyncio

6
推荐指数
2
解决办法
1628
查看次数

标签 统计

async-await ×1

python ×1

python-asyncio ×1