python web03-线程-02-多任务-线程
import threading
import time
def test1():
for i in range(5):
time.sleep(1)
print("-----test1---%d---" % i)
def test2():
for i in range(5):
time.sleep(1)
print("-----test2---%d---" % i)
def main():
# 1、设定线程标号
t1 = threading.Thread(target=test1)
t2 = threading.Thread(target=test2)
# 查看当前未启动线程个数
print(threading.enumerate())
# 2、先启动t1线程
t1.start()
time.sleep(1)
print("---1---")
# 查看启动T1后的线程个数
print(threading.enumerate())
# 3、再启动T2线程
t2.start()
time.sleep(1)
print("---2---")
#打印启动 T1,T2后的线程个数
print(threading.enumerate())
if __name__ == "__main__":
main()