python队列join
生活随笔
收集整理的這篇文章主要介紹了
python队列join
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
如果要讓一個任務隊列按照順序進行,則必須使用join,代碼如下:
''' Created on Dec 23, 2013@author: long ''' import threading from threading import Thread import timeclass Thread1(Thread):'''classdocs'''def __init__(self,thread_name):'''Constructor'''Thread.__init__(self,name=thread_name)def run(self):'''run method'''count = 0while True:print ('thread--',self.getName(),",count:",count)time.sleep(0.5)count = count + 1if count > 10:breakdef main():for y in range(1, 3):thread1 = Thread1('longthread' + str(y))thread1.start()if thread1.isAlive():thread1.join()for i in range(50):print ('main:', i)if __name__ == "__main__":main()結果是先執行名為'longthread1',再'longthread2',再是主進程,所以thread1.join()的意思是等thread1執行完,再去執行其他線程。
轉載于:https://www.cnblogs.com/stefanlee/p/3488251.html
總結
以上是生活随笔為你收集整理的python队列join的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: clang 搭建和编译boost 和ze
- 下一篇: dedecms标签使用