1.线程启动
def run(n):
print('%s in thread...'%n)
t=threading.Thread(target=run,args=(n,))
t.start
#线程等待
t.join
2.多线程同时启动并等待执行结果
def run(n):
print('%s in thread...'%n)
t_res=[]
for i in range(10)
t=threading.Thread(target=run,args=(n,))
t.start
t_res.append(t)
for t in t_res:
#线程等待
t.join
3.守护线程
for i in range(10)
t=threading.Thread(target=run,args=(n,))
t.setDaemon(True)
t.start
4.队列queue,使程序解耦,提高效率
import queue
q=queue.Queue
q.input(1)
q.get()