基于生成器的协程与本地协程 [英] Generator-based coroutine versus native coroutine

查看:99
本文介绍了基于生成器的协程与本地协程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚阅读了 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.

推荐答案

功能没有区别.使用asyncawait关键字的本地协程"只是以前在基于发电机的协程"中实现的语法糖.

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文档中建议使用asyncawait 如果不需要支持较旧的Python版本.

这篇关于基于生成器的协程与本地协程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆