重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

threading.Timer延迟执行实例代码

threading.Timer 实现延迟执行的实例代码

import time
import threading
import logging

FORMAT = "%(asctime)s %(threadName)s %(thread)d %(message)s"
logging.basicConfig(format=FORMAT, level=logging.INFO)

def worker():
    logging.info('in worker')
    time.sleep(2)

t = threading.Timer(5, worker)
t.setName('w1')
# t.cancel()   # 尝试减少等待时间对比
t.start()
print(threading.enumerate())
# t.cancel()  # 尝试取消注释对比
time.sleep(8)  # 尝试减少等待时间对比
print(threading.enumerate())

当前名称:threading.Timer延迟执行实例代码
转载源于:http://cqcxhl.com/article/pjpjgg.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP