python定时器

2019-03-06  本文已影响0人  yancoding

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()
上一篇 下一篇

猜你喜欢

热点阅读