fcond = threading.Condition()
fargs = set()

def f(x):
    with fcond:
        while x in fargs:
            fcond.wait()
fargs.add(x)
with fcond:
    fargs.remove(x)
fcond.notify_all()
Garbage-collect a lock once no threads are asking for it