线程 Threading

import time
from threading import Thread
def func():
while True:
time.sleep(0.5)
print(123)
def func2():
print("func2 start ")
time.sleep(3)
print("func2 end")
t1 = Thread(target=func)
t2 = Thread(target=func2)
t1.setDaemon(True) #将t1变成守护线程
t1.start()
t2.start()
print("主线程代码结束")

输出

func2 start

主线程代码结束

123

123

123

123

123

func2 end

posted @ 2018-09-24 20:21  云丛  阅读(84)  评论(0编辑  收藏  举报