For the first time in contact with the Python programming language of the friend, just beginning to learn python multi-threading, the Python multi-
threaded This aspect of the understanding is relatively small, in this article we will learn about
Python multi-Threading advantages . Needless to say, we begin to study in this article.
Python multithreading
Multithreading is similar to executing several different programs at the same time, multithreaded operation has the following advantages:
1. Threads can be used to put tasks that occupy a long period of time in the background to handle.
2. The user interface can be more attractive, such as the user clicked a button to trigger the processing of certain events, you can pop up a progress bar to show the progress of processing
3. The program may run faster
4. Threads are useful when waiting tasks are implemented such as user input, file read and write, and network send and receive data. In this case we can release some precious resources such as memory footprint and so on.
5. Threads can be preempted (interrupted).
6. Threads can be temporarily shelved (also called sleep) while other threads are running-this is the thread's concession.
Multithreading for IO-intensive, such as sockets, crawlers, web
Threads are still different from the process during execution. Each separate thread has a program run entry, sequence of sequence execution, and exit of the program. However, threads cannot be executed independently, and must be dependent on the application, which provides multiple threads of execution control.
Each thread has his own set of CPU registers, called the thread's context, which reflects the state of the CPU register on which the thread last ran the thread.
The instruction pointer and stack pointer registers are the two most important registers in the thread context, and threads are always run in the context of the process, which is used to flag memory in the process address space of the owning thread.