这里介绍一下python中定时任务:sched
python中自带的是sched,也可以通过pip下载schedule进行任务定时处理,这里先简单介绍下sched的使用
import datetime import schedule import time import sched schedule2=sched.scheduler(time.time,time.sleep) def fun2(string1): # time.sleep(10) print("now is ",time.time(),"====",string1,"==string2=") def fun3(string1): # time.sleep(10) print("now is ",time.time(),"====",string1,"==fun3=") def fun4(string1): # time.sleep(10) print("now is ",time.time(),"====",string1,"==fun4=") def run2(): # print(1) # enter之后可带的参数意义:delay, priority, action, argument=() # delay表示执行周期,也就是多久之后开始执行 # priority表示执行优先等级,1~10的优先级排序,1为最先执行者 # action执行的函数名 # argument表示函数带的参数,以{}形式封装 schedule2.enter(1, 1, fun2,{"goods1"}) schedule2.enter(1, 2, fun2,{"goods2"}) schedule2.enter(1, 3, fun2,{"goods3"}) schedule2.enter(1, 4, fun3, {"goods4"}) schedule2.enter(1, 5, fun4, {"goods5"}) schedule2.enter(1, 6, fun3, {"goods6"}) schedule2.enter(1, 7, fun4, {"goods7"}) schedule2.run()