|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import threading
import time
class MyThread(threading.Thread):
def __init__(self,id):
threading.Thread.__init__(self)
def run(self):
while 1:
time.sleep(1)
print ("This is " + self.getName())
if __name__ == "__main__":
t1=MyThread(999)
t1.setDaemon(True)
t1.start()
print ("I am the father thread.")
>>>
I am the father thread.
>>> This is Thread-1
This is Thread-1
This is Thread-1
设置了t1.setDaemon(True)
为什么主线程结束了,不杀死子线程?
py2和py3都不行
不要在ide里执行,我以前用多进程也出现过这种情况
正确做法是在cmd 里执行
|
|