admin管理员组

文章数量:1794759

python 定时任务schedule

python 定时任务schedule

step 1 # 准备好任务 ,假设我们要定时执行的任务是sayhello函数 test.py

def sayhello(name): print('hello time scheduler'+name) if __name__ == '__main__': sayhello()

step 2 # 任务函数交给schedule定时执行 runtask.py

import schedule import time from test import sayhello # 00:30 # schedule.every().day.at(""00:30"").do(sayhello,name='parhat') schedule.every().second.do(sayhello,name='parhat') while True: schedule.run_pending() time.sleep(1)

注:需要安装schedule包

pip install schedule

Appedex # 定时任务示例

schedule.every(10).minutes.do(sayhello) schedule.every().hour.do(sayhello) schedule.every().day.at("10:30").do(sayhello) schedule.every(5).to(10).minutes.do(sayhello) schedule.every().monday.do(sayhello) schedule.every().wednesday.at("13:15").do(sayhello)

本文标签: Pythonschedule