def __init__(self, path, _keep=False):
        "By default, unflock/close the file immediately after setting the lock"
        self.file = file = open(path, 'a')
        locked = _lockonly(file)
        if _keep:
            self.locked = locked
        else:
            file.close()
            self.locked = False
By default, unflock/close the file immediately after setting the lock
recipes/Python/577404_fcntlflock_Unix_file_lock_behaviour_sampling/recipe-577404.py