#-*- coding:utf-8 -*-
from threading import Thread
from time import sleep
class MyThread(Thread):
def run(self):
for i in range(1, 100, 1):
print(i)
sleep(100)
def daemon(n):
for i in range(1, n, 1):
sleep(100)
print(i)
def main():
#守护线程,当主线程和 线程t运行完,程序终止,不会等 thread 运行
thread = MyThread()
thread.setDaemon(True)
thread.start()
#非守护线程 程序需要等 t运行完成才退出
t = Thread(target=daemon, args=(100,))
t.start()
print("main")
main()