import threading,time,random #查看线程的数量 def sing(): for i in range(3): print('正在唱歌....%d'%i) time.sleep(random.random()*10) def dance(): for i in range(3): print('正在跳舞....%d'%i) time.sleep(random.random()*10) if __name__ == "__main__": print("时刻关注新技术,晚会开始:%s"%time.ctime()) t1 = threading.Thread(target=sing) t2 = threading.Thread(target=dance) t1.start() t2.start() while True: #输出线程数 length = len(threading.enumerate()) print("当前运行的线程数为:%d"%length) time.sleep(1) if length <= 1: break