@contextmanager
def bounce_lock(name):
    lockfile = '/var/lock/%s.lock' % name
    fd = open(lockfile, 'w')
    remove = False
    try:
        fcntl.lockf(fd, fcntl.LOCK_EX | fcntl.LOCK_NB)
        remove = True
        yield
    except IOError:
        raise LockHeldException("Service %s is already being bounced!" % name)
    finally:
        fd.close()
        if remove:
            os.remove(lockfile)
Acquire a bounce lockfile for the name given. The name should generally
dataset/ETHPy150Open Yelp/paasta/paasta_tools/bounce_lib.py/bounce_lock