python用schedule模块实现定时任务

python用schedule模块实现定时任务import scheduleimport timedef test():print("Im working...")def test2():print(&qu

python用schedule模块实现定时任务

import schedule
import time
 
def test():
    print("I'm working...")
def test2():    
    print("I'm working... in job2")
 
# 每10分钟执行一次job函数
schedule.every(10).minutes.do(test)
# 每10秒执行一次job函数
schedule.every(10).seconds.do(test)
# 当every()没参数时默认是1小时/分钟/秒执行一次job函数
schedule.every().hour.do(test)
schedule.every().day.at("10:30").do(test)
schedule.every().monday.do(test)
# 具体某一天某个时刻执行一次job函数
schedule.every().wednesday.at("13:15").do(test)
# 可以同时定时执行多个任务,但是每个任务是按顺序执行
schedule.every(10).seconds.do(job2)
# 如果job函数有有参数时,这么写
schedule.every(10).seconds.do(job,"参数")
while True:
    # 启动服务
    schedule.run_pending()
    time.sleep(1)

发布者:admin,转转请注明出处:http://www.yc00.com/web/1755003025a5225661.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信