가장 간단한 방법은 당신이 다시 함수를 호출하기 전에 대기 할 시간을 알 때까지 타이머를 다시 시작하지 아마도 : 그 어떤 이유로 할 수없는 경우
def examplebdc():
wordv = 'asdfsdfm'
if any("m" in s for s in wordv):
print("new post")
threading.Timer(60*60, examplebdc).start()
else:
threading.Timer(50, examplebdc).start()
examplebdc()
을, 당신은 변경할 수 있습니다 나중에 참조하고 취소 할 수 있도록 당신이 당신의 타이머를 생성하고 시작하는 방법 :
def examplebdc():
# lets assume we need to set up the 50 second timer immediately
timer = threading.Timer(50, examplebdc) # save a reference to the Timer object
timer.start() # start it with a separate statement
wordv = 'asdfsdfm'
if any("m" in s for s in wordv):
print("new post")
timer.cancel() # cancel the previous timer
threading.Timer(60*60, examplebdc).start() # maybe save this timer too?
examplebdc()
당신의 단일 기능 이것은 쉽게, 그냥 변수를 사용할 수 있습니다. 타이머가 다른 곳에서 시작 되었다면 타이머 참조를 전달하기 위해 하나 이상의 global
문이나 좀 더 복잡한 논리를 사용해야 할 수도 있습니다.
['time.sleep()'] (https://docs.python.org/2/library/time.html#time.sleep)? – NPE
@ NPE 나는 그것을 시험해 보았다. 멈추거나 멈추지 않습니다. –