python线程对象join的用法

来源:互联网 发布:新的淘宝店怎么推广 编辑:程序博客网 时间:2024/05/19 13:58

一 代码

import threadingimport timedef func1(x, y):    for i in range(x, y):        print(i, end=' ')    print()    time.sleep(10)t1=threading.Thread(target = func1, args = (15, 20))t1.start()t1.join(5)t2=threading.Thread(target = func1, args = (5, 10))t2.start()#t2.join() #the program will not continue until t2 thread finishsprint(t1.isAlive())time.sleep(2) #try to comment this line to see the different resultprint(t2.isAlive())

 

二 运行结果
E:\python\python可以这样学\第13章 多线程与多进程编程\code>python SecondExample.py
15 16 17 18 19
5 6 7 8 9
True
True