tags: Python
JOIN () Method: Use the Cameraup_Thread.Join () method to ensure that the thread is executed and then execute the next Cameraup_thread thread.
Moreover, the JOIN () method does not only stop the next process, and it will prevent this loop from being performed, and the loop in which the thread is located will not be performed down when the thread is not completed.
import threading
import time
def run():
time.sleep(2)
Print ('The name of the current thread is:', threading.current_thread (). Name)
time.sleep(2)
if __name__ == '__main__':
start_time = time.time()
Print ('This is the main thread:', threading.current_thread (). Name)
thread_list = []
for i in range(5):
t = threading.Thread(target=run)
t.start()
nowtime = time.time()
PRINT ('Current Process Start Time, determining whether the Join method blocks the thread to prevent the loop execution', NOWTIME)
t.join()
Print ('Determines if the Join method blocks the loop execution If the last thread is not executed,')
Print ('main thread ends!', threading.current_thread (). name)
Print ('a total of:', time.time () - start_time)
The execution result of the above code:

As shown in the figure above, i = 1, execute the first thread T, when the thread T is not executed, the program does not perform the print ('judging whether the Join method prevents the execution of the cycle if the JOIN method is When the last thread is not executed, the cycle has not continued because if the loop continues to execute, then a lot of print should be printed. If the JOIN method is blocked, if the execution of the loop is not performed. At the time '), it means that many threads have been stacked. But not, all the Join () methods block the execution of all code behind the thread, and the code behind () only waiting for the thread to perform the end, it can continue.
The effect of the join() method in Python multithreading and multiprocessing is the same. Take multithreading as an example: The work done by join is thread synchronization, that is, after the task of...
Article Directory When no join is added, the relationship between the main thread and the child thread is verified Code operation result When using join, the relationship between the main thread and t...
Use Join to set all the index strings of the list together, which can quickly form a corpus in NLP....
Reference link:[Mo people Python] Threading learns multithreaded python Reference link:Moperse multithreading Reference link:Threading - parallelism based on thread testThreading3_1.py testThreading3_...
The ForkJoin framework, which can do synchronous and asynchronous processing, can be called with return values and no return values. invokeAll is a synchronous call; Execute is an asynchronous call;...
Heaven will pity the grass, the world will be sunny If there are two threads at the same time, thread A (main thread) and thread B. The execution time of thread B takes 5 seconds, then after calling t...
Application and analysis of join under multithreading 1. Scenario: Multi-threaded environment 2. Requirements: If there are two threads, how to ensure the sequential execution of threads 3. Solution: ...
Origin Join () role: Let the "main thread" wait for the "sub-thread" to continue to run. This sentence may be a bit awkward, we still understand examples Description: There are two...
JON Usage Environment: After the main thread process is completed, the results of the sub-thread are required, that is, the main thread needs to wait for the sub-thread execution to end. The first is ...