IO model of Python concurrent programming

Source: Internet
Author: User

One: Introduction to IO Model

What is the difference between synchronous (synchronous) IO and asynchronous (asynchronous) Io, what is blocking (blocking) IO and non-blocking (non-blocking) IO respectively? The problem is that different people may give different answers, such as wikis, that asynchronous IO and non-blocking io are a thing. This is because different people have different backgrounds, and the context is not the same when discussing this issue. Therefore, in order to better answer this question, I first limit the context of this article.

This article discusses the background of network IO in a Linux environment. The most important reference in this document is Richard Stevens's UNIX? Network Programming Volume 1, third edition:the Sockets Networking ", 6.2 section" I/O Models ", Stevens in this section detailing the features and differences of various IO, if English is good enough , it is recommended to read directly. The style of Stevens is famous, so don't worry about it. The flowchart in this paper is also intercepted from the reference literature.

To better understand the IO model, we need to know: synchronous, asynchronous, blocking, non-blocking. (Contex)

Sync (synchronous):

Asynchronous (asynchronous):

Blocking (blocking)

Non-blocking (non-blocking)

For a network IO (read example), he would involve two system objects, one calling the IO process (or thread) and the other being the system kernel (kernel). When a read operation occurs, the operation goes through a single phase:

1: Waiting data (waiting for the READG)

2: Copying data from the kernel to the process (Copying the data from the kernel to the)

Two: Blocking io (bloking io)

In Linux, all sockets are blocking by default.

When the user process invokes the RECVFROM system call, Kernel begins the first phase of IO: Preparing the data. For network IO, there are times when the data has not arrived at the beginning (for example, a full UDP packet has not been received), and kernel waits for enough data to arrive.

On this side of the user process, the entire process is blocked. When kernel waits until the data is ready, it copies the data from the kernel to the user's memory, and then kernel returns the result, and the user process removes the block state and re-runs it.

IO model of Python concurrent programming

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.