@asyncio.coroutine vs async def

前端 未结 3 1166
傲寒
傲寒 2020-12-04 17:33

With the asyncio library I\'ve seen,

@asyncio.coroutine
def function():
    ...

and

async def function():
             


        
3条回答
  •  死守一世寂寞
    2020-12-04 18:11

    async def is a new syntax from Python 3.5. You could use await, async with and async for inside async defs.

    @coroutine is a functional analogue for async def but it works in Python 3.4+ and utilizes yield from construction instead of await.

    For practical perspective just never use @coroutine if your Python is 3.5+.

提交回复
热议问题