有没有理由在 async/await 上使用 Python 的基于生成器的协程?
Is there any reason to use Python's generator-based coroutines over async/await?
尽管其众所周知的 "one way to do it" 理念,Python(从 3.5 版开始)支持两种编写协程的方式:
- enhanced generators (perhaps with
yield from
)
async
and await
.
假设我们只需要支持 Python >= 3.5 的版本。是否有必要使用旧的、基于生成器的协程?还是基于 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.
尽管其众所周知的 "one way to do it" 理念,Python(从 3.5 版开始)支持两种编写协程的方式:
- enhanced generators (perhaps with
yield from
) async
andawait
.
假设我们只需要支持 Python >= 3.5 的版本。是否有必要使用旧的、基于生成器的协程?还是基于 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.