【问题标题】:What part of asyncio is concurrent? Would like implementation detailsasyncio 的哪一部分是并发的?想要实现细节
【发布时间】:2016-12-17 23:40:15
【问题描述】:

asyncio模块的描述是:

这个模块提供了编写单线程的基础设施 使用协程的并发代码,通过套接字多路复用 I/O 访问 和其他资源,运行网络客户端和服务器,以及其他 相关原语。

我一直在阅读有关新的和非凡的 asyncio python 模块/包/whatever 的信息。我知道有 python GIL,因此 asyncio 非常适合 GIL,因为(目的是)您使用单个线程上的事件循环来管理事物。那么什么是并发呢?好吧,I/O 似乎是并发的。我相信 I/O 操作是由操作系统处理的。那么在 asyncio 的内部,它是否编写了一个并发的 C 扩展来利用操作系统给定的功能?

【问题讨论】:

标签: python concurrency python-asyncio


【解决方案1】:

在asyncio中,单线程IO并发是通过结合很多概念来实现的:

future -------------------+---------+
                          |         |
generator ---> coroutine -+-> task -+-> base event loop -+-> selector event loop
                                                         |
select ---> selector ------------------------------------+

然而,没有期货也可以达到同样的目的,正如curio所证明的那样:

generator ---> coroutine -+-> task -+-> kernel
                                    |
select ---> selector ---------------+

链接

Standard library:

Asyncio:

Curio:

【讨论】:

  • curio 是 asyncio2
猜你喜欢
  • 2017-07-24
  • 1970-01-01
  • 1970-01-01
  • 2016-02-24
  • 2011-12-21
  • 1970-01-01
  • 1970-01-01
  • 2015-05-21
  • 1970-01-01
相关资源
最近更新 更多