threading.Timer定时

cooolr 于 2021-11-05 发布

Timer(interval, function, args=None, kwargs=None) 创建定时器

cancel() 取消定时器

start() 使用线程方式执行

join(self, timeout=None) 等待线程执行结束

from threading import Timer

def hello():
    print(f"当前线程数: {len(threading.enumerate())}")
    Timer(10, hello).start()

hello()