#coding:utf-8
import time
import threading
def countdown(n):
while n>0:
print('T-minus',n)
n -= 1
time.sleep(3)
if __name__ == '__main__':
t=threading.Thread(target=countdown,args=(10,),daemon=True)
t.start()
if t.is_alive():
print('still running')
else:
print('Complete.')
run结果: 没有输出。
python控制台运行结果:正常输出
只看你贴出来的代码,需要把daemon=True去掉;
daemon=True是设置当前线程为守护线程,而如果剩下的线程只有守护线程的话,python程序就直接退出了。
看你贴出来的代码,就是这种情况,只有一个线程,而且是守护线程,那么python程序就退出了。
感谢。