The difference between blocking and non-blocking is where the difference between synchronous IO and asynchronous IO is.
Blocking vs non-blocking: Calling blocking IO will block the corresponding process until the operation is complete, and non-blocking IO will return immediately if the kernel also prepares the data.
synchronous IO VS asynchronous IO:
synchronous IO做”IO operation”的时候会将process阻塞
The previously described blocking io,non-blocking Io,io multiplexing are all part of the synchronous IO category, and the asynchronous I/O. One might say that non-blocking io is not block. Here is a very "tricky" place, defined in the "IO operation" refers to the real IO operation, is the example of recvfrom this system call. Non-blocking IO does not block the process when it executes recvfrom this system call if the kernel data is not ready. However, when the data in the kernel is ready, recvfrom copies the data from the kernel to the user's memory, at which point the process is blocked, during which time the process is block. The asynchronous IO is not the same, and when the process initiates an IO operation, the direct return is ignored until the kernel sends a signal telling the process that IO is complete. Throughout this process, the process has not been blocked at all.
Comparison of each IO model:
As described above, the difference between non-blocking io and asynchronous io is obvious. In non-blocking io, although the process will not be blocked for most of the time, it still requires the process to go to the active check, and when the data is ready, it is also necessary for the process to proactively call Recvfrom to copy the data to the user's memory. and asynchronous Io is completely different. It's like a user process handing over an entire IO operation to someone else (kernel) and then sending a signal notification when someone finishes it. During this time, the user process does not need to check the status of the IO operation, nor does it need to actively copy the data.
Python concurrent Programming: IO Model comparison analysis