我调用了这个类的静态函数,希望它每3秒运行一次,只运行5次。。但它不是在计数器=5处停止,而是继续运行
我找了又找系统出口(0)可以停止计时器。怎么了?你知道吗
def senLogtoBackup():
threading.Timer(3, senLogtoBackup).start()
AccessLog.AccessLog.backupAccessLog("logbackups","example.log")
try:
senLogtoBackup()
if AccessLog.AccessLog.Counter == 5:
sys.exit(0) # expects I it will terminate the timer. but it still counts
类别定义:
class AccessLog:
Counter =0
@staticmethod
def backupAccessLog(target, source):
AccessLog.Counter+=1
print "counter",AccessLog.Counter
你找错了,看看os._exit
您应该使用“t.cancel”停止计时器。你知道吗
相关问题 更多 >
编程相关推荐