@asyncio.coroutine vs async def
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: With the asyncio library I've seen, @asyncio.coroutine def function(): ... and async def function(): ... used interchangeably. Is there any functional difference between the two? 回答1: Yes, there are functional differences between native coroutines using async def syntax and generator-based coroutines using the asyncio.coroutine decorator. According to PEP 492 , which introduces the async def syntax: Native coroutine objects do not implement __iter__ and __next__ methods. Therefore, they cannot be iterated over or passed to iter() , list() ,