我有一个while循环作为我的主要功能。在其中我检查了几个 IF 语句并相应地调用函数。如果在最后两分钟内已经运行了一个特定的功能,我不想调用它。我不想在函数中添加 WAIT() 语句,因为我希望在此期间执行其他 IF 测试。
在尝试暂停 myFunction() 之前,代码是这样的
while not(exit condition):
if(test):
otherFunction()
if(test):
otherFunction()
if(test):
myFunction()
我希望 myFunction() 最多每两分钟运行一次。我可以在其中放置一个 wait(120) ,但这会阻止在那个时候调用 otherFunction() 。
我试过
import time
set = 0
while not(exit condition):
if(test):
otherFunction()
if(test):
otherFunction()
if(test):
now = time.clock()
diff = 0
if not(set):
then = 0
set = 1
else:
diff = now - then
if (diff > 120):
myFunction()
then = now
没有成功。不确定这是否是正确的方法,如果是,则此代码是否正确。我第一次在 Python 中工作(实际上是 Sikuli),我似乎无法通过跟踪执行来查看它是如何执行的。