守护线程和守护进程最大的区别是:守护进程是当主进程运行结束时,被守护的进程也立马结束,但是守护线程不是,只有当非守护线程运行完毕,主线程才会运行完毕
from threading import Threadimport timedef foo(): print(123) time.sleep(1) print("end123")def bar(): print(456) time.sleep(3) print("end456")if __name__ == '__main__': t1=Thread(target=foo) t2=Thread(target=bar) t1.daemon=True t1.start() t2.start() print("main-------")