import functools


def with_lock(lock):
    """Make sure the lock is held while in this function."""

    def decorator(func):
        @functools.wraps(func)
        def _with_lock(*args, **kwargs):
            with lock:
                return func(*args, **kwargs)

        return _with_lock

    return decorator