def with_lock(method):
    """
    Execute method with lock. Instance should have lock object in lock attribute.
    """
    def wrapper(self, *args):
        with self.lock:
            return method(self, *args)
    return wrapper