@contextmanager
def flock(filename=None):
    with open(filename, 'a') as fh:
        _flock(fh, LOCK_EX)
        yield
        _flock(fh, LOCK_UN)
simple blocking exclusive file locker
dataset/ETHPy150Open Netflix/aminator/aminator/util/linux.py/flock