← 都来码 / Dolaima← 例程索引python/school/_unsupported/032_ThreadDaemon.py 原文

python/school/_unsupported/032_ThreadDaemon.py · 411 字节 · 下载原文

import threading
import time

class mythread(threading.Thread):
    def __init__(self, num, threadname):
        threading.Thread.__init__(self, name = threadname)
        self.num = num

    def run(self):        
        time.sleep(self.num)
        print(self.num)

t1 = mythread(1, 't1')
t2 = mythread(5, 't2')
t2.daemon = True
# t2.setDaemon(False)
print(t1.daemon)
print(t2.daemon)

t1.start()
t2.start()