尽管其著名的“一种方法”理念,Python(从 3.5 版开始)支持两种编写协程的方法:
- enhanced generators (可能与
yield from) -
asyncandawait.
假设我们只需要支持 >= 3.5 的 Python 版本。是否有必要使用旧的、基于生成器的协程?还是基于 async/await 的协程完全取代基于生成器的协程?
请您参考如下方法:
[...] 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.
