Skip to content

TimeWatcher

The TimeWatcher monitors the execution time of the command/function. It can be created using the capsula.TimeWatcher.__init__ method.

capsula.TimeWatcher.__init__

__init__(name: str = 'execution_time')
PARAMETER DESCRIPTION
name

Name of the time watcher. Used as a key in the output.

TYPE: str DEFAULT: 'execution_time'

Source code in capsula/_watcher/_time.py
def __init__(
    self,
    name: Annotated[str, Doc("Name of the time watcher. Used as a key in the output.")] = "execution_time",
) -> None:
    self._name = name
    self._duration: timedelta | None = None

Configuration example

Via capsula.toml

[in-run]
watchers = [
  { type = "TimeWatcher" },
]

Via @capsula.watcher decorator

import capsula

@capsula.run()
@capsula.watcher(capsula.TimeWatcher("calculation_time"))
def func(): ...

Output example

The following is an example of the output of the TimeWatcher, reported by the JsonDumpReporter:

"time": {
  "calculation_time": "0:00:00.000798"
}