Module server.decorators

Helper decorators

Functions

def timed(*args, **kwargs)

Record the execution time of a function and log a warning if the time exceeds a limit.

Examples

>>> import time, mock
>>> log = mock.Mock()
>>> @timed(logger=log, limit=0.05)
... def foo():
...    time.sleep(0.1)
>>> foo()
>>> log.warning.assert_called_once()
def with_logger(cls)

Add a _logger attribute to a class. The logger name will be the same as the class name.

Examples

>>> @with_logger
... class Foo:
...    pass
>>> assert Foo._logger.name == "Foo"