1. 报错情况:
python2.7 APScheduler库中 backgroundshcheduler 参数“cron” 当设置 second="*"时,定时任务可以执行,但是当设置为:minute=“*”, 定时任务无法执行。
2. 原因之一:
APScheduler版本太高,尤其对于Py2.7来说,版本太高,不是很友好
3. 解决方法:
降版本 例如 APScheduler==3.0.1
ps:就这个问题,困扰了2天,又找不到更好的替代库,实在没招了,才侥幸试一试,结果,嘿~他娘的,还真是版本问题。
例:
# coding=utf-8 import time import os from apscheduler.schedulers.background import BackgroundScheduler def tick(): print('〖{}〗定时任务运行' .format(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))) if __name__ == '__main__': scheduler = BackgroundScheduler() scheduler.add_job(tick, 'cron', minute="*") # 整分钟执行 scheduler.start() # 这里的调度任务是独立的一个线程 print('Press Ctrl+{0} to exit'.format('Break' if os.name == 'nt' else 'C')) try: while True: time.sleep(1) # 其他任务是独立的线程执行 print('【{}】sleep!'.format(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))) except (KeyboardInterrupt, SystemExit): scheduler.shutdown() print('Exit The Job!')