基于生成器的协程与本地协程

编程入门 行业动态 更新时间:2024-10-24 13:26:58
本文介绍了基于生成器的协程与本地协程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

更多推荐

基于生成器的协程与本地协程

本文发布于:2023-11-23 10:02:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1621040.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:生成器

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!