multi-threaded & multi-process in Python
Use Python multiprocessing (multiprocessing) enables multiple CPU can work at the same time, greatly enhance the utilization efficiency.
IO-intensive and CPU intensive
CPU-intensive: linear program execution, CPU intensive, always close to 100% (eg: replacing a large number of regular text matching)
IO-intensive: a lot of time spent waiting for program I/O operation, CPU always idle, at about 10% (such as network request)
multi-threaded and multi-process
Python multi-threaded and other programming languages are very different from the multi-threaded, Python multi-threaded even in the multi-core CPU host can only use a CPU, not the true sense of the concurrent implementation.
For IO-intensive programs, the use of multi-threaded technology can wait at intervals of CPU blocking the implementation of other operations, you can improve CPU efficiency.
For CPU-intensive programs, the original CPU is a busy state, forced the use of multi-threaded technology, will not increase the efficiency of CPU use, but increase the cost of thread switching, may lead to multi-threaded implementation efficiency is not as single-threaded Implementation efficiency. In the multi-core CPU, a host can use python multi-process (multiprocessing) makes the program using multiple CPU, you can achieve the program in the real sense of the parallel (the number of processes does not exceed the CPU core).
Run the Python program to monitor CPU usage, Only one CPU is in use
Run the Python program, monitor the use of the CPU can be seen that 11 CPU are in 100% of the use of state