程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Understanding of learning notes for Python introductory development comparison of IO models

編輯:Python

The point of this section

  • Understand each IO Model comparison

The duration of this section needs to be controlled 15 Within minutes

IO Comparative analysis of models

up to now , There are already four IO Model It's all over . Now go back to the first few questions :blocking and non-blocking What's the difference between ,synchronous IO and asynchronous IO What's the difference between .
Answer the simplest one first :blocking vs non-blocking. In fact, the previous introduction has clearly explained the difference between the two . call blocking IO Will always be block Live in the corresponding process until the operation is completed , and non-blocking IO stay kernel If the data is ready, it will return immediately .

 Further explanation synchronous IO and asynchronous IO Before the difference , We need to define them first .Stevens The definition given ( It's actually POSIX The definition of ) It looks like this :
A synchronous I/O operation causes the requesting process to be blocked until that I/O operationcompletes;
An asynchronous I/O operation does not cause the requesting process to be blocked;
The difference between the two is synchronous IO do ”IO operation” Will be process Blocking . By this definition , four IO Models can be divided into two categories ,
As mentioned before blocking IO,non-blocking IO,IO multiplexing All belong to synchronous IO This kind of , and asynchronous I/O The latter category .
Someone might say ,non-blocking IO Not by block ah . Here's a very “ The cunning ” The place of , The definition of ”IO operation” It means the real IO operation ,
It's in the example recvfrom This system call.non-blocking IO In execution recvfrom This system call When , If kernel The data is not ready ,
Not at this time block process . however , When kernel When the Chinese data is ready ,recvfrom Will transfer data from kernel Copy to user memory , At this time the process is being block 了 ,
In the meantime , The process is being block Of . and asynchronous IO Is not the same , When the process starts IO After the operation , Just go straight back and ignore , until kernel Send a signal ,
Tell the process to say IO complete . In the whole process , The process has not been block.
each IO Model The comparison is shown in the figure :

After the introduction above , Will find non-blocking IO and asynchronous IO The difference is still obvious . stay non-blocking IO in , Although the process will not be block, But it still requires the process to be proactive check, And when the data is ready , It also needs the process to call again recvfrom To copy data to user memory . and asynchronous IO It's totally different . It's like the user process will take the whole IO The operation was handed over to others (kernel) complete , And then they signal when they're done . in the meantime , User processes don't need to check IO State of operation , There's no need to actively copy data .


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved