이것을 실행하면 1 분 정도 기다렸다가 '켜짐'이 인쇄되고 2 분 정도 기다렸다가 '꺼짐'이 인쇄됩니다. 그 후에 apscheduler는 열매를 맺는 것처럼 보이고 빨리 2 개 사이에서 빨리 교체됩니다.왜 작동하지 않습니까? 이것은 apscheduler 버그입니까?
나는 apscheduler 버그에 넘어 지거나 왜 이런 일이 발생합니까?
from datetime import datetime, timedelta
import time
import os, signal, logging
logging.basicConfig(level=logging.DEBUG)
from apscheduler.schedulers.background import BackgroundScheduler
scheduler = BackgroundScheduler()
def turn_on():
#Turn ON
print('##############################Lights on')
def turn_off():
#Turn off
print('#############################Lights off')
def schedule():
print('Lights will turn on at'.format(lights_on_time))
if __name__ == '__main__':
while True:
lights_on_time = (str(datetime.now() + timedelta(minutes=1)))
lights_off_time = (str(datetime.now() + timedelta(minutes=2)))
scheduler.add_job(turn_on, 'date', run_date=lights_on_time)
scheduler.add_job(turn_off, 'date', run_date=lights_off_time)
try:
scheduler.start()
signal.pause()
except:
pass
print('Press Ctrl+{0} to exit'.format('Break' if os.name == 'nt' else 'C'))
try:
# This is here to simulate application activity (which keeps the main thread alive).
while True:
time.sleep(2)
except (KeyboardInterrupt, SystemExit):
# Not strictly necessary if daemonic mode is enabled but should be done if possible
scheduler.shutdown()
패키지에 익숙하지 않지만 절대 시간을 예약 했으므로 여기에 놀라움이 없습니다 – volcano
나는이 스크립트에 여전히 문제가 있습니다. 그것은 하나의 사이클을 거치고 나서 계속 트리거 오류 메시지를 놓친다. 어떤 아이디어? TIA –