美文网首页
python定时器

python定时器

作者: yancoding | 来源:发表于2019-03-06 10:45 被阅读0次

1.超时执行

# --*-- coding: utf-8 --*--

import threading

def time_handler():
    print('hello')

timer = threading.Timer(5, time_handler)
timer.start()

2.周期执行

# --*-- coding: utf-8 --*--

import threading

def time_handler():
    print('hello')
    global timer
    timer = threading.Timer(5, time_handler)
    timer.start()

if __name__ == '__main__':
    time_handler()

相关文章

网友评论

      本文标题:python定时器

      本文链接:https://www.haomeiwen.com/subject/zazzuqtx.html