1

The description of the asyncio module is:

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.

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?

itzjustricky
  • 423
  • 1
  • 4
  • 14
  • 1
    Stack Overflow is neither a forum nor a tutorial service. This is a Q&A site where *specific* programming questions (usually, but not always, including some code) get *specific* answers. Please take the [tour] and carefully read through the [help] to learn more about the site, including [what is on-topic](http://stackoverflow.com/help/on-topic) and [what is not](http://stackoverflow.com/help/dont-ask), and how to [ask a good question](http://stackoverflow.com/help/how-to-ask). Please also follow the [question checklist](http://meta.stackoverflow.com/q/260648). – MattDMo Dec 18 '16 at 00:16

1 Answers1

7

In asyncio, single-threaded IO concurrency is achieved by combining many concepts:

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

However, it is possible to achieve the same purpose without futures, as proven by curio:

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

Links

Standard library:

Asyncio:

Curio:

Vincent
  • 12,919
  • 1
  • 42
  • 64