# coding utf-8
# file threaddaemon.py
import threading
import time
class mythread(threading.Thread):
def __init__(self,threadname):
threading.Thread.__init__(self,name=threadname)
def run(self):
time.sleep(5)
print self.getName()
def func():
t1.start()
print 'func1 done'
def func2():
t2.start()
print 'func2 done'
t1=mythread('t1')
t2=mythread('t2')
t2.setDaemon(True)
func()
func2()
本文介绍了Python中线程的概念,详细阐述了如何创建线程并实现线程间的同步操作,重点讲解了线程的守护属性及其应用,通过实例演示了如何在主线程结束时自动关闭非守护线程。
1852

被折叠的 条评论
为什么被折叠?



