oslo_concurrency.watchdog
¶
Watchdog module.
New in version 0.4.
- oslo_concurrency.watchdog.watch(logger, action, level=10, after=5.0)¶
Log a message if an operation exceeds a time threshold.
This context manager is expected to be used when you are going to do an operation in code which might either deadlock or take an extraordinary amount of time, and you’d like to emit a status message back to the user that the operation is still ongoing but has not completed in an expected amount of time. This is more user friendly than logging ‘start’ and ‘end’ events and making users correlate the events to figure out they ended up in a deadlock.
- Parameters
logger – an object that complies to the logger definition (has a .log method).
action – a meaningful string that describes the thing you are about to do.
level – the logging level the message should be emitted at. Defaults to logging.DEBUG.
after – the duration in seconds before the message is emitted. Defaults to 5.0 seconds.
Example usage:
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"