参考链接:http://www.cnblogs.com/alex3714/articles/5230609.html
1 import threading,time 2 3 def run(n): 4 print("task",n) 5 time.sleep(2) 6 print("task done",n) 7 8 start_time = time.time() 9 t_objs = [] 10 for i in range(50): 11 t = threading.Thread(target=run,args=("t-%s"%i,)) 12 t.start() 13 t_objs.append(t) 14 15 for t in t_objs: 16 t.join() 17 18 print("------all threads has finished....") 19 print("cost:",time.time()-start_time) 20 21 # t1 = threading.Thread(target=run,args=("t1",)) 22 # t2 = threading.Thread(target=run,args=("t2",)) 23 # t1.start() 24 # t2.start() 25 26 # run("t1") 27 # run("t2")