如何终止python中的计时器线程 [英] how to terminate a timer thread in python
本文介绍了如何终止python中的计时器线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个代码来运行一个计时器线程,它每 x 秒做一次工作,它没有问题
i have a code to run a timer thread and its doing a job every x seconds and its has no problem
import threading
import datetime
def starThread():
t = threading.Timer(0, Do_Analysis())
t.start()
def Do_Analysis():
#define threading.Timer to do the job every x secound
t=threading.Timer(1, Do_Analysis).start()
print('datetime is : ',datetime.datetime.now())
print(threading.active_count)
starThread()
我需要在某个时候终止线程,但我不知道该怎么做任何人都可以请指导我
i need to terminate the thread at some point and i dont know how to do it can anyone please guide me
推荐答案
做这样的事情:
t=threading.Timer(1, Do_Analysis)
t.start()
if True:
t.cancel()
这篇关于如何终止python中的计时器线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文