I. Introduction of the Association Process
The topic in this section is to implement concurrency based on a single thread, that is, to implement concurrency with only one main course (obviously the only CPU available), so we need to look back at the nature of Concurrency: toggle + save State . The CPU is running a task that, in both cases, will be cut off to perform other tasks (the switchover is controlled by the operating system), one case is that the task is blocked, and the other is that the task has taken too long to calculate or has a higher priority program to replace it.
PS: When introducing the process theory, the three execution states of the process are mentioned, and the thread is the execution unit, so it can also be understood as the three states of the thread
One: The second situation does not improve efficiency, just to allow the CPU to rain equitably, to achieve the seemingly all tasks are "simultaneous" effect, if more than one task is pure calculation, this switch will reduce efficiency. For this we can verify based on yield. Yield itself is a way to save the running state of a task in a single thread, so let's review it briefly:
Python path--python basic 12--concurrent Programming