编程语言
首页 > 编程语言> > python 定时器

python 定时器

作者:互联网

非常简单的一个东西,原本以前是flask框架写网站的时候用过,这次是用定时器只是为了实时更新数据而已,想着没必要用flask上的办法,就网上随便抄了个,结果我屮艸芔茻,,,算了自己记录下来以免下次被哪写那些牛鬼蛇神(SB)给忽悠瘸了,害得我这么晚下班

import time
import os
from apscheduler.schedulers.blocking import BlockingScheduler
def tick():
    print('Tick! The time is: %s' %(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(int(time.time())) )),"执行一次")

if __name__ == '__main__':
    scheduler = BlockingScheduler()
    scheduler.add_job(tick, 'interval', seconds=3)
    print('Press Ctrl+{0} to exit'.format('Break' if os.name == 'nt' else 'C'))
    scheduler.start()

效果图如下

 

 

标签:__,定时器,python,scheduler,time,print,import,tick
来源: https://blog.csdn.net/weixin_50699509/article/details/121777111