【发布时间】:2018-03-31 12:09:02
【问题描述】:
基于生成器的协程似乎有两种:
-
来自a reply 吉姆·法萨拉基斯·希利亚德:
基于生成器的协程:由
types.coroutine包装的生成器 (def+yield)。你需要把它包起来types.coroutine如果您需要将其视为协程对象。 -
从 Python in a Nutshell,它没有明确地调用它 “基于生成器的协程”:
当您基于
asyncio编写 Python 代码时(理想情况下也使用 来自 asyncio.org 的附加模块),您通常会编写 协程函数。最高包括 Python 3.4,此类函数 是使用“yield”中涵盖的yield from语句的生成器 来自 (v3-only)”,第 95 页,用@asyncio.coroutine装饰, 在第 518 页的“异步协程”中进行了介绍;从 https://www.python.org/dev/peps/pep-0492/#differences-from-generators
基于生成器的协程(对于 asyncio 代码必须用 @asyncio.coroutine 修饰)
http://masnun.com/2015/11/13/python-generators-coroutines-native-coroutines-and-async-await.html 也称它为“基于生成器的协程”。
这两种基于生成器的协程是同一个概念吗?
如果不是,它们在用途和用途上有什么区别?
谢谢。
【问题讨论】:
标签: python python-3.x asynchronous generator coroutine