threading.Timer 延迟执行实例代码
threading.Timer 实现延迟执行的实例代码
import timeimport threadingimport loggingFORMAT = "%(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())
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。