Multiple tasks can be performed using multi-threaded or multi-process.
Multiple processes, the same variable, each with a copy in each process, not affecting
In multi-threading, all variables are shared by all threads. And the switch between the threads is the system to dispatch, cannot control, so may
Multiple threads in a process may invoke the value of a variable at the same time, causing confusion in the value of the variable, when the thread lock is introduced, but the thread lock is prone to deadlock and prevents multithreading.
In addition, the Python interpreter because of the design of the Gil Global lock, resulting in multithreading can not take advantage of multicore. Multi-threaded concurrency is a beautiful dream in Python.
In thread and process, the process should be preferred because the process is more stable and the process can be distributed over multiple machines, while the thread is most
Can only be distributed to multiple CPUs on the same machine.
Multi-process consumes more resources, and the number of processes supported by the system is limited, although the running task is more stable
A single threaded thread crash can cause the entire process to crash, and threads a global lock.
Asynchronous IO Support, you can use a single-process single-threaded model to perform multitasking, a new model called the event-driven model.
The co-process is an asynchronous IO support mode. The process of this seed program can be interrupted at execution time, waiting for the time-consuming operation to notify the main thread after the message is sent,
Then proceed from where it was just interrupted. In this way, the switching between tasks is controlled by the internal definition of the program, and does not require a lock, and the execution efficiency is high.
Coroutine and multithreading, multi-process