欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

python线程对象join的用法

程序员文章站 2022-04-12 22:53:08
...

一 代码

import threading
import time
def 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 finishs
print(t1.isAlive())
time.sleep(2) #try to comment this line to see the different result
print(t2.isAlive())

 

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