我刚刚阅读了 PEP0492 ,这是关于协程的新方法,但是PEP无法使我理解基于生成器的协程和本地协程之间的区别.有人可以告诉我有什么区别(也许有例子)吗?
I just read PEP0492 talking about the new approach on coroutines but the PEP failed to make me understand the difference between generator-based coroutines and native ones. Can someone tell me the difference (maybe with examples)?
据我所知,他们使用不同的词(yield/yield from and await/async/yield).我知道在原生协程结束时会产生产量,但是对于基于生成器的协程也是如此.
For what I understood they uses different words (yield/yield from and await/async/yield). I understand that at the end of a native coroutine a yield is expected, but this also stands true for generator-based ones.
推荐答案功能没有区别.使用async和await关键字的本地协程"只是以前在基于发电机的协程"中实现的语法糖.
There is no functional difference. "Native coroutines" using the async and await keywords are just syntactic sugar for what was previously implemented in "generator-based coroutines."
在 3.5文档中建议使用async和await 如果不需要支持较旧的Python版本.
更多推荐
基于生成器的协程与本地协程
发布评论