The concept interview questions

Processes, threads, coroutines difference?

Process: the minimum unit for allocation of computer resources, essentially for processing data isolation.

Thread: cpu used to calculate the smallest unit, the thread is really used to doing things.

A process can have multiple threads. An application can have multiple processes. But because Python GIL lock specific reason, and it makes the difference such as multi-threaded Java language,

At the same time, a process that only one thread can be cpu scheduling. So when dealing with compute-intensive data, we need to open multiple processes to achieve high efficiency.

In dealing with io-intensive data, you can use multiple threads to improve efficiency. Because io operation does not take up cpu thread.

GIL lock control process, in essence, is the underlying C language Python's locked up.

Coroutine: in fact, micro-threads. Slicing thread, at different times, a plurality of thread scheduling sheets encountered io operation, go perform other operations. When the result of the processing operation io back, it will switch back.

Coroutine itself does not exist, the block is executed in order to achieve the programmer control code generated. Python implementation module greenlet coroutine achieve coroutine + IO module operation may be used gevent

Single-threaded concurrency:

Coroutine switching + IO: module gevent 

Based on the non-blocking IO framework of the event loop: Twisted

 

Guess you like

Origin www.cnblogs.com/wen-kang/p/11298727.html