python调用接口数据怎么设置定时器,没30分钟刷新一次

# 1.简单的 time.sleep + while

import time

 

def test_api():

    print("test_api_log")

     

while True:

    test_api()

    time.sleep(60*30)

     

     

     

# 2.时间调度模块 sched

import time, os, sched 

   

# 第一个参数确定任务的时间,返回从某个特定的时间到现在经历的秒数 

# 第二个参数以某种人为的方式衡量时间 

schedule = sched.scheduler(time.time, time.sleep) 

   

def perform_command(cmd, inc): 

     # 安排inc秒后再次运行自己,即周期运行 

     schedule.enter(inc, 0, perform_command, (cmd, inc)) 

     os.system(cmd) 

    

def timming_exe(cmd, inc = 60): 

     # enter用来安排某事件的发生时间,从现在起第n秒开始启动 

     schedule.enter(inc, 0, perform_command, (cmd, inc)) 

     # 持续运行,直到计划时间队列变成空为止 

     schedule.run() 

    

if __name__ == __"main"__:  

    print("show time after 10 seconds:"

    timming_exe("echo %time%"10)

 

# scheduler.enter(delay,priority,func,args)

# 第一个参数是一个整数或者float,代表多少秒后执行这个任务

# 第二个参数priority是优先级,0代表优先级最高,1次之,2次次之

# 第三个参数就是你要执行的任务,可以简单的理解成你要执行的函数的函数名

# 第四个参数是你要传入的这个定时执行的action为函数名的函数的参数,最好是用"()"括号来包起来,包起来肯定是不会出错的。--

# --其次,当你只传入一个参数时,用括号包起来后,一定要记住再打上一个逗号。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值