threading.Timer延迟执行实例代码-大悟县灿优商贸网站建设

关于灿优商贸

多方位宣传企业产品与服务 突出企业形象

公司简介 公司的服务 荣誉资质 新闻动态 联系我们

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://www.apyobr.com/article/pjpjgg.html

其他资讯