守护线程和守护进程

守护进程随着主进程的代码的执行结束而结束

守护线程会在主线程结束之后等待其他子线程的结束才结束(如有其他子线程,没有其他子线程就是主线程结束守护线程随之结束)

import time
from threading import Thread

def func1():
    while True:
        print("*"*10)
        time.sleep(1)
def func2():
    print("in func2")
    time.sleep(5)
t1 = Thread(target=func1)
t1.daemon = True
t1.start()
t2 = Thread(target=func2)
t2.start()
print("主线程结束")

猜你喜欢

转载自www.cnblogs.com/superniao/p/10126395.html