Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
969 views
in Technique[技术] by (71.8m points)

python - What part of asyncio is concurrent? Would like implementation details

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...