asyncio模块的描述是:
This module provides infrastructure for writing single-threaded concurrent code using coroutines, multiplexing I/O access over sockets and other resources, running network clients and servers, and other related primitives.
我一直在阅读关于新的和非凡的 asyncio python 模块/包/任何东西的信息。我知道有 python GIL,因此 asyncio 非常适合 GIL,因为(目的是)您可以在单个线程上使用事件循环来管理事物。那么什么是并发呢?好吧,看来 I/O 似乎是并发的。我相信 I/O 操作是由操作系统处理的。那么在asyncio的内部,是否写了一个利用操作系统给定函数的并发C扩展?
请您参考如下方法:
在asyncio中,单线程IO并发是通过结合很多概念来实现的:
future -------------------+---------+
| |
generator ---> coroutine -+-> task -+-> base event loop -+-> selector event loop
|
select ---> selector ------------------------------------+
但是,正如 curio 所证明的那样,没有 future 也可以达到同样的目的。 :
generator ---> coroutine -+-> task -+-> kernel
|
select ---> selector ---------------+
链接
Asyncio :
Curio :
