【发布时间】:2019-05-25 22:16:06
【问题描述】:
Python 可以在等待 asyncio.sleep 和 aiohttp 函数时切换上下文。 python 最终如何知道上下文何时需要切换?如果我想实现自己的 IO 功能,我们需要调用哪些 API?
基于http://www.dabeaz.com/coroutines/Coroutines.pdf,我们可以在使用yield编程时使用select api让上下文切换。在带有异步和等待的python 3中,它仍然是唯一的方法吗?
【问题讨论】:
-
看看同一作者的newer lecture。虽然它仍然基于生成器,但它使用
yield from构造作为构建块,在功能上等同于await(实际上,Python 2.5+await是yield from的一个瘦包装器)。跨度>
标签: python python-3.x asynchronous async-await python-asyncio