python线程对象的daemon属性 博客分类: python pythondaemon
程序员文章站
2024-02-09 11:44:46
...
一 代码
import threading import time class mythread(threading.Thread): def __init__(self, num, threadname): threading.Thread.__init__(self, name = threadname) self.num = num #self.daemon = True 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()
二 运行结果
E:\python\python可以这样学\第13章 多线程与多进程编程\code>python ThreadDaemon.py
False
True
1