守护线程

import time
from threading import Thread

def func1():
    while True:
        print('*'*10)
        time.sleep(1)

def func2():
    print('in func2')
    time.sleep(5)

t = Thread(target=func1,)
t.daemon = True
t.start()
t2 = Thread(target=func2,)
t2.start()
# t2.join()
print('主线程')

 

import time
from threading import Thread,Lock

def func():
    print(666)
    time.sleep(10)

def func2():
    pass

t = Thread(target=func)
t.daemon = True
t.start()
print('主线程')

 

import time
from threading import Thread,Lock

def func():
    while True:
        print('*'*10)
        time.sleep(1)
def func2():
    print('in func2')
    time.sleep(5)

t = Thread(target=func)
t.daemon = True
t.start()

t2 = Thread(target=func2)
t2.start()

print('主线程')

 

posted @ 2018-09-10 09:20  Woowo  阅读(82)  评论(0编辑  收藏  举报