Python threads are implemented using thread and threading. It is better to take advantage of threading because thread is not protected by threads, and when the main thread exits, the child threads are forced to quit. The threading supports the daemon thread.
The common method in thread: Thread.allocate_lock () is to return a new locked object
Acquire ()/release () is the two states of the original lock, locking and unlocking, which is the operation of the locked object established above.
Thread.start_new_thread (func, parameter of func) is the creation of a new thread, where the first two parameters must be filled, and if the function does not require arguments, pass in an empty tuple.
Use of threading:
Create a thread:
Threading. Thread (target = Youfunc,args = (your func ' s args))
Start ()
Start thread activity
Join ()
Waiting for thread to terminate
After all the threads have been created, call the start () function together to start, instead of creating a startup one. And, instead of managing a bunch of locks (assigning locks, acquiring locks, releasing locks, checking the state of locks, etc.), simply call the join () function on each thread.
Join () waits until the thread ends, or when the timeout parameter is given, until the timeout is reached. Another important aspect of join () is that it can not be called at all. Once the thread is started, it runs until the thread's function ends and exits.
Excerpt from the Insect Guru's blog.
Threads thread thread notes for Python