Difference in python threads, processes and coroutines

 

  1. Process is a unit of resource allocation
  2. Thread scheduling unit is the operating system
  3. Coroutine, also called micro-threads, shred, coroutine context switching is only a simple operation of the CPU resources is small, high efficiency
  4. The process of switching resources are needed most, inefficient
  5. A program has at least one process, a process has at least one thread
  6. Thread execution overhead is small, but not conducive to the management and protection of resources; and the process contrary

Popular Description

  • There is a boss wants to open a factory for the production of an item (such as scissors)
  • He needs to spend some financial and material resources to make a production line, this production line has a lot of these devices and material resources to be able to produce all of the scissors prepared called: Process
  • Only the production line is not able to produce, so the boss to find workers for production, the workers are able to make use of these materials will eventually step by step scissors to do it, to do this thing called the workers: Thread
  • The boss in order to increase productivity, think of three kinds of ways:
    1. In this production line hiring enough workers to do the scissors together, so that efficiency is doubled zo long, that is, single-process multiple threads
    2. Boss found this production line workers is not possible, because after all, limited resources and a production line of the material, so the boss has spent some financial and material resources to purchase another production line, and then recruit such workers again step in improving the efficiency of some of the that multi-process multi-threaded mode
    3. The boss found, now has a lot of production lines, and each line has a lot of the workers (ie the program is multi-process, there are a number of threads per process), again in order to improve efficiency, the boss thought of a loss trick, states: If a temporary employee at work or nothing to wait for certain conditions (such as waiting for the other workers after completion of the production processes seek him to work again), then the employees will use this time to do other things, so in other words: If a thread is waiting for some conditions, can take advantage of this time to do other things, in fact, that is: coroutine way

https://blog.csdn.net/weixin_42589922?t=1

Guess you like

Origin www.cnblogs.com/applelife/p/10983551.html