Verification of the role of join in python only multithreading

tags: Python  Multithreading

When no join is added, the relationship between the main thread and the child thread is verified

Code

import threading
import time


def wait2s():
    time.sleep(2)
    print('we have sleep 2s')


if __name__=="__main__":
    t=threading.Thread(target=wait2s)
    t.start()
    print('main thread over')
    print(t.is_alive())

operation result

When using join, the relationship between the main thread and the child thread

Code:

import threading
import time


def wait2s():
    time.sleep(2)
    print('we have sleep 2s')


if __name__=="__main__":
    t=threading.Thread(target=wait2s)
    t.start()
    t.join()
    print('main thread over')
    print(t.is_alive())

operation result

Intelligent Recommendation

Python :can only join an iterable

BeautifulSoup traverses the news.baidu.com <li> node, according to the two file storage methods in the figure can get the corresponding file generation, but when cmd runs the py file, such as th...

An example shows the role of join() and daemon() in python

When a process starts, it will generate a main thread by default, because the thread is the smallest unit of the program execution flow. When setting up multiple threads, the main thread will create m...

The role of python multi-process kind join() function

Runtime when using multiple processes without blocking with the join function 2, when only one join is called, the main process that is called will wait for the child process to continue to execute do...

I first met setDaemon and join in Python multithreading.

Normal multithreaded code operation result Result analysis Both threads are running normally and ending normally, main end is output normally when the thread executes setDaemon test operation result R...

Python - threading multithreading difference between setDaemon and join

2019 Unicorn Enterprise Heavy Gold Recruitment Python Engineer Standard >>> Python can easily use the threading package to achieve multithreading Thread objects have two methods for managing ...

More Recommendation

Threading understand the join () function: Python multithreading

You can get through the following example to join () function returns: If the thread is a child thread, then call thread.join () role is to ensure that the next sub-thread after thread can execute one...

Some understanding of threading join() and setDaemon() in Python multithreading

join([timeout]) : join():In main thread A, child thread B is created, and B.join() is called in main thread A, then main thread A will be inCall place to waitUntil the child thread B completes the ope...

Python multithreading join method and daemon thread

Great god please detour Comparison of Python multithreading and multiprocessing When using Python, when is it suitable to use multithreading? When is it suitable to use multiple processes? For io oper...

Python- multithreading blocking (join) and daemon thread (setDaemon)

Preface Today, Xiao Wang invited Xiaoming and Xiaowang to eat hot pot. After the hot pot, there will be the following three scenes: Scene 1: Xiao Wang (main) has finished eating first, Haihai (guest) ...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top