python 定时任务schedule

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/weixin_38570967/article/details/83663616

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)

猜你喜欢

转载自blog.csdn.net/weixin_38570967/article/details/83663616