Python multi-thread and python multi-thread programming
Python multithreading is similar to executing multiple different programs at the same time. multithreading has the following advantages: using threads, you can place tasks in programs that take a long time to the background for processing. The user interface can be more attractive. For example, if a user clicks a button to trigger processing of some events, a progress bar can be popped up to display the processing progress. The running speed of the program may be accelerated in the implementation of some pending tasks, such as user input, file read/write, and network data sending and receiving. The thread is more useful. In this case, we can release some precious resources, such as memory usage. The execution process of a thread is different from that of a process. Each Independent thread has a program running entry, sequence execution sequence, and program exit. But the thread cannot be executed independently. It must exist in the application and the application provides multiple thread execution control. Each thread has its own set of CPU registers, called the thread context, which reflects the status of the CPU registers that the thread ran last time. The instruction pointer and stack pointer register are the two most important registers in the thread context. threads always run in the context of the process. These addresses are used to mark the memory in the process address space that owns the thread. The thread can be preemptible (interrupted ). When other threads are running, the thread can be temporarily shelved (also called sleep)-this is the concession of the thread. There are two ways to start learning the Python thread Python to use threads: functions or classes to wrap thread objects. Function: Call the thread model ..
Python Multithreading
The join operation is to block the main thread. When the main thread stops, it will not continue until all the sub-threads exit.
By default, once the main thread exits, the program is terminated. To ensure that other threads complete the task, the main thread must be blocked and the other threads are finished before proceeding to the next step.
Python Multithreading
It calls fun () separately, for example, the code in the fun function is inserted in both threads. However, these two threads share the variables of the fun function. To avoid code exceptions, we recommend that you first understand thread communication before writing code.