异步的哪一部分是并发的?想要实施细节 [英] What part of asyncio is concurrent? Would like implementation details
问题描述
asyncio模块的描述为:
The description of the asyncio module is:
该模块提供了使用协程编写单线程
并发代码的基础结构,通过套接字
和其他资源进行I / O访问,运行网络客户端和服务器以及其他与
相关的原语。
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扩展,以利用操作系统提供的功能?
I have been reading about the new and extraordinary asyncio python module/package/whatever. I understand there is the python GIL and so the asyncio properly fits well with the GIL since (the intention is) you manage things with an event loop on a single thread. So what is concurrent? Well it seems that the I/O seems to be concurrent. I believe I/O operations are handled by the operating system. So in the internals of asyncio, does it write a concurrent C-extension that utilizes functions given by the operating system?
推荐答案
在异步,单线程IO并发是通过结合许多概念来实现的:
In asyncio, single-threaded IO concurrency is achieved by combining many concepts:
future -------------------+---------+
| |
generator ---> coroutine -+-> task -+-> base event loop -+-> selector event loop
|
select ---> selector ------------------------------------+
但是,如古玩:
generator ---> coroutine -+-> task -+-> kernel
|
select ---> selector ---------------+
链接
标准库:
- generator
- select
- selector
- native coroutine
异步:
- asyncio coroutine
- asyncio future
- asyncio task
- base event loop
- selector event loop
Curio :
- curio coroutine
- curio task
- curio kernel
这篇关于异步的哪一部分是并发的?想要实施细节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!