首页 » 开发 » python » python定时进行某项任务的程序

python定时进行某项任务的程序

 

python周期性运行程序可以使用

while True:
    print("暂停60s")
    time.sleep(60) #60s暂停

也可以学https://www.jianshu.com/p/ab8d9e576ac4里一样

#coding=utf-8
import datetime,time
xiacishijian = datetime.datetime(2018,3,8,21,46,50,0)
while True:
    shijishijian = datetime.datetime.now()
    if xiacishijian <= shijishijian <= (xiacishijian + datetime.timedelta(seconds = 1)):
        print("现在的时间是%s" % shijishijian)
        time.sleep(1)
        xiacishijian = xiacishijian + datetime.timedelta(minutes = 1)
        print("下次运行时间为%s" % xiacishijian)

原文链接:python定时进行某项任务的程序,转载请注明来源!

1