# *_*coding:utf-8 *_* import time import threading def sing(): for i in range(5): print("唱山歌咯"+ str(i)); time.sleep(1) def dance(): for i in range(5): print(‘跳舞‘+str(i)) time.sleep(1) def main(): t1 = threading.Thread(target=sing) t2 = threading.Thread(target=dance) t1.start() // 这个时候线程才创建 t2.start() while True: time.sleep(1) length = len(threading.enumerate()) print("当前线程数"+str(length)) if __name__ == "__main__": main() print("结束")
查看当前线程数量
线程创建后 执行顺序不确定 主线程结束 子线程也会结束
原文:https://www.cnblogs.com/php-linux/p/12774947.html