with lock:
    return f(*args, **kw)

does the job in only 2 lines ;)