from apscheduler.schedulers.blocking import BlockingScheduler
import time
class Status():
def __init__(self, value):
self.value = value
s1 = Status(False)
print(s1.value)
sched = BlockingScheduler()
def run_task():
if s1.value == True:
localtime = time.asctime(time.localtime(time.time()))
print("{} 任务启动".format(localtime))
else:
localtime = time.asctime(time.localtime(time.time()))
print("{} 关闭任务。。。。。".format(localtime))
# 每天10:00分执行一次
@sched.scheduled_job('cron', day_of_week='*', hour='9', minute='33', second='0')
# @sched.scheduled_job('cron', day_of_week='*', hour='*', minute='*', second='10')
def scheduled_job():
s1.value = True
run_task()
print('》》》》》')
# 每天16:00分执行一次
@sched.scheduled_job('cron', day_of_week='*', hour='9', minute='34', second='0')
# @sched.scheduled_job('cron', day_of_week='*', hour='*', minute='*', second='15')
def scheduled_job2():
s1.value = False
run_task()
print('-----')
sched.start()
print("let us figure out the situation")
result.png