def sync(lock):
    """
    A synchronization decorator
    """
    def sync(f):
        @wraps(f)
        def new_function(*args, **kwargs):
            lock.acquire()
            try:
                return f(*args, **kwargs)
            finally:
                lock.release()
        return new_function
    return sync
A synchronization decorator