python_守护线程

守护线程:

只要主线程运行完,无论子线程是否运行完,都会结束。

import threading,time
def lajifenlei():
    time.sleep(2)
    print('干垃圾')
for i in range(10):
    th=threading.Thread(target=lajifenlei)
    th.setDaemon(True)  #把子线程设置成守护线程
    th.start()
print('完成')
原文地址:https://www.cnblogs.com/hancece/p/11243257.html