计划程序之上的Python计划程序

问题描述

我有一个计划在每个星期一上午9:00进行的功能

运行该计划后,我需要每小时重复一次该功能

这是我的代码

import schedule
import time

def main_job():
    print('Hello World')

def schech():
    schedule.every().minute.do(main_job)

    while True:
        schedule.run_pending()
        time.sleep(1)


schedule.every().day.at("17:46").do(schech)

while True:
    schedule.run_pending()
    time.sleep(1)

我得到的错误

RecursionError:超过最大递归深度

解决方法

删除schech()函数中的while循环。

import schedule
import time

def main_job():
    print('Hello World')

def schech():
    main_job()
    schedule.every(60).minutes.do(main_job)

schedule.every().day.at("9:00").do(schech)

while True:
    schedule.run_pending()
    time.sleep(1)