# `oslo_concurrency.watchdog`

Watchdog module.

Added in version 0.4.

oslo_concurrency.watchdog.watch(logger: Logger, action: str, level: int = 10, after: float = 5.0) → Generator[None, None, None]

  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"

this page last updated: 2026-04-14 09:41:44

Except where otherwise noted, this document is licensed under Creative Commons Attribution 3.0 License. See all OpenStack Legal Documents.

found an error? report a bug