oslo_concurrency.watchdog¶
看门狗模块。
在 0.4 版本中添加。
- oslo_concurrency.watchdog.watch(logger, action, level=10, after=5.0)¶
如果操作超过时间阈值,则记录一条消息。
预期将此上下文管理器用于代码中可能发生死锁或花费大量时间的操作,并且希望向用户发出一条状态消息,表明操作仍在进行中,但未在预期时间内完成。这比记录“开始”和“结束”事件,并让用户关联事件以确定最终陷入死锁更方便。
- 参数:
logger – 符合 logger 定义的对象(具有 .log 方法)。
action – 描述您即将执行的事情的有意义的字符串。
level – 应发出消息的日志级别。默认为 logging.DEBUG。
after – 在发出消息之前持续的秒数。默认为 5.0 秒。
示例用法
FORMAT = '%(asctime)-15s %(message)s' logging.basicConfig(format=FORMAT) LOG = logging.getLogger('mylogger') with watchdog.watch(LOG, "subprocess call", logging.ERROR): subprocess.call("sleep 10", shell=True) print "done"