1.線(xiàn)程啟動(dòng)
創(chuàng)新互聯(lián)主營(yíng)堆龍德慶網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營(yíng)網(wǎng)站建設(shè)方案,app軟件定制開(kāi)發(fā),堆龍德慶h5微信小程序搭建,堆龍德慶網(wǎng)站營(yíng)銷(xiāo)推廣歡迎堆龍德慶等地區(qū)企業(yè)咨詢(xún)
def run(n):
print('%s in thread...'%n)
t=threading.Thread(target=run,args=(n,))
t.start
#線(xiàn)程等待
t.join
2.多線(xiàn)程同時(shí)啟動(dòng)并等待執(zhí)行結(jié)果
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:
#線(xiàn)程等待
t.join
3.守護(hù)線(xiàn)程
for i in range(10)
t=threading.Thread(target=run,args=(n,))
t.setDaemon(True)
t.start
4.隊(duì)列queue,使程序解耦,提高效率
import queue
q=queue.Queue
q.input(1)
q.get()