我正在使用此代码doSomething每 3 秒调用一次函数。但我想要那个时候numeroPeticiones== 3,停止这样做。我找了很多例子,但没有一个有效。就我而言,即使numeroPeticiones== 3满足的条件,我的函数仍将永远执行。我该如何解决?
import threading
from threading import Timer
numeroPeticiones=0
def doSomething():
global numeroPeticiones
numeroPeticiones=numeroPeticiones+1
print ("hello, world",numeroPeticiones)
if numeroPeticiones == 3:
print("cancel")
t.cancel()
def set_interval(func, sec):
def func_wrapper():
set_interval(func, sec)
func()
t = threading.Timer(sec, func_wrapper)
t.start()
return t
明月笑刀无情
相关分类