我调用了类的静态函数,并且预计它将每3秒运行一次并且只运行5次..但它不会在计数器= 5处停止,继续运行
我搜索并发现sys.exit(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