有什么理由在async/await上使用Python的基于generatorbased的协同程序吗?

2024-04-24 22:01:18 发布

您现在位置:Python中文网/ 问答频道 /正文

尽管Python(从3.5版起)支持两种编写协同程序的方法,但它的“一种方法”理念是众所周知的:

  1. enhanced generators(可能带有{a2})
  2. ^{} and ^{}。在

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


Tags: and方法gt版本a2asyncawait理念
1条回答
网友
1楼 · 发布于 2024-04-24 22:01:18

引用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.

相关问题 更多 >