绕进去没绕出来,在死胡同里越绕越深。
出去上了个厕所,豁然开朗。
不就是想每5分钟运行一个命令,只允许一次吗?
正确的思路:
import timer
import time
import os
while True:
if timer.func(5) is True:
print "Do Something"
time.sleep(60) #直接睡过去一分钟不就好了吗?
print time.ctime()[11:-5]
所以说,发现问题解决不了的时候要及时跳开,想想到底想要什么,而不是拘泥于细节死扣。
越死扣,越着急,越解决不了。
程序的作用是在00,05,10,15,20,25,30,....这种特定的分钟跳出循环执行命令。可以用来使重复采样实现。
# Countdown Timer
# Designed By Xc.Li @ Mar.2016
# coding = utf-8
import time
import os
def func(mode):
if mode == 5:
check_point = [00, 05, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55]
if mode == 10:
check_point = [00, 10, 20, 30, 40, 50]
if mode == 15:
check_point = [00, 15, 30, 45]
if mode == "test":
check_point = [00, 10, 20, 23]
while True:
current_minute = time.ctime()[14:-8]
for item in check_point:
if str(item) == current_minute or current_minute == '00':
print "Check Point!"
time.sleep(5)
return True
print "Waiting at mode %d" % mode
time.sleep(5)
os.system("cls")