python定时器

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定时器)