python - 有什么理由使用 Python 的基于生成器的协程而不是 async/await 吗?

标签 python asynchronous async-await generator coroutine

尽管 Python(从版本 3.5 开始)有着众所周知的“一种方法”理念,但它支持两种编写协程的方法:

  1. enhanced generators (也许与 yield from )
  2. async and await .

假设我们只需要支持 Python >= 3.5 的版本。是否有必要使用旧的、基于生成器的协程?或者基于 async/await 的协程是否完全取代基于生成器的协程?

最佳答案

引用Guido van Rossum himself :

[...] eventually we'll always be using async functions when coroutines are called for, dedicating generators once again to their pre-PEP-342 role of a particularly efficient way to implement iterators.

关于python - 有什么理由使用 Python 的基于生成器的协程而不是 async/await 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39671950/

相关文章:

Node.js 模块从 MongoDB 数据库获取数据

c# - "Async All the Way Down": Well, 底部到底是什么?

node.js - 为什么我的异步代码在 Controller 中有效,而在模型中无效?

python - 无法在 Django 设置文件中获取环境变量

Python HL7 Listener 套接字消息确认

python - 计算不同长度的 3 维数组的平均值

python - 问题转换较旧的 MITMProxy 脚本以在 5.2 上工作 - 替换时出错并且无法找到有关替换内容的文档

javascript - 如何等到循环内的异步进程完成后再退出循环?

javascript - Array.prototype.some() 异步

c# - asp .net MVC 5 中的异步任务