赞
踩
通过定时来执行任务,我们日常工作生活中会经常用到。python有schedule这个库,简单好用,比如,可以每秒,每分,每小时,每天,每天的某个时间点,间隔天数的某个时间点定时执行,另外自己又写了一个可以自定义时间点来定时执行任务,代码如下。
import schedule
import time
class Timing():
#按秒循环定时执行任务
def doEverySecond(self,seconds,job_func):
try:
schedule.every(seconds).seconds.do(job_func)
while True:
schedule.run_pending()
except Exception as e:
raise e
# 按分钟循环定时执行任务
def doEveryMinutes(self,minutes,job_func):
try:
schedule.every(minutes).minutes.do(job_func)
while True:
schedule.run_pending()
except Exception as e:
raise e
# 按小时循环定时执行任务
def doEveryHours(self,Hours,job_func):
try:
schedule.every(Hours).minutes.do(job_func)
while True:
schedule.run_pending()
except Ex
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。