#coding=utf-8
import threading
from time import ctime,sleep
def music(func):
for i in range(5):
print "I was listening to %s. %s" %(func,ctime())
print threading.currentThread()
sleep(2)
def move(func):
for i in range(2):
print "I was at the %s! %s" %(func,ctime())
print threading.currentThread()
sleep(50)
threads = []
T1 = threading.thread (target = music, args = (u 'love sale ",))
threads.append(t1)
T2 = threading.thread (target = Move, args = (u 'Avatar',))
threads.append(t2)
if __name__ == '__main__':
for t in threads:
t.setDaemon(True)
t.start()
t.join()
print "all over %s" % ctime()
We only add a JOIN () method for the above program to wait for the thread to terminate. Join () The role is that the parent thread of this sub-thread will have been blocked until the sub-thread is running.
Note: The location of the join () method is outside the for loop, that is, after the two processes in the FOR cycle must be completed, the master process is issued.
2019 Unicorn Enterprise Heavy Glour Recruitment Python Engineer Standard >>> Fork / join is used for calculation; sorting comparison The data in the lower list, the current formation of the p...
Join is equivalent to the operation of the jacket Main threads and divided threads belong to concurrent threads are multiple thread objects if using Join Make a thread prioritize the remaining obstruc...
Look at the code first Join merged thread. After using Join, the main thread will block, and only after the thread is executed...
Thread enforcement Thread.join (); Method thread is enforced JOIN combined thread, after the thread is executed, do other threads Thread enforcement case jacket Explanation: When the sub-thread and th...
http://www.verejava.com/?id=16992940862472 http://www.verejava.com/?id=16992940862472...
http://www.verejava.com/?id=16992940862472 http://www.verejava.com/?id=16992940862472...
The deadlock caused by yourself cannot be unlocked Reentrant lock Alternative methods for reentrant locks Condition variables for thread synchronization Thread synchronization queue Inter-thread commu...
When involving Python multi-threaded programming, there are four special concepts that need everyone to understand: the main thread, sub-thread, daemon, and threads. The default of the article knows t...
Python threading- single-thread multi-thread main threader thread setdeamon join Single thread Multithreading Main thread and sub-thread setDaemon() join() Test the time of multi-threading procedures ...