守护线程:只要主线结束,那么子线程立即结束,不管子线程有没有运行完成。
import threading,time
def run(): time.sleep(3) print('哈哈哈')
for i in range(50): t = threading.Thread(target=run) t.setDaemon(True) #把子线程设置成为守护线程 ---- 当主线程结束后,子线程也会立即结束,不管有没有运行完成 t.start()
print('Done,运行完成。')# time.sleep(3)
转载于:https://www.cnblogs.com/lynn-chen/p/9117984.html
相关资源:JAVA上百实例源码以及开源项目