import sched,time
def loopTask():
print('定时任务执行')
count = 0
loopcount = 5
# 定义一个函数,用于在调度器中反复添加任务
def add_task_repeatedly(a_sched, interval, function, argument=()):
a_sched.enter(interval, 1, add_task_repeatedly, argument=(a_sched, interval, function, argument))
function(*argument)
# global count,loopcount
# print(type(count),type(loopcount),loopcount)
# if count < loopcount:
# count += 1
# else:
# return True
s = sched.scheduler(time.time, time.sleep)
add_task_repeatedly(s, 5, loopTask)
s.run()
python创建定时任务
原创
©著作权归作者所有:来自51CTO博客作者hanwqyq的原创作品,请联系作者获取转载授权,否则将追究法律责任

提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
创建 PostgreSQL 备份脚本并设置定时任务
在linux中进行PostgreSQL 备份脚本并设置定时任务
sql 日志文件 PostgreSQL -
设置定时任务,别再写死了!动态定时任务真的太爽了!
设置定时任务,别再写死了!动态定时任务真的太爽了!
spring 触发器 cron表达式