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
- 下一篇: Python 2 中文乱码解决方案: