a guest Dec 12th, 2018 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- import fcntl
- from contextlib import contextmanager
- def flocked(fd):
- """ Locks FD before entering the context, always releasing the lock. """
- fcntl.flock(fd, fcntl.LOCK_EX)
- fcntl.flock(fd, fcntl.LOCK_UN)
- if __name__ == "__main__":
- with open('test') as f:
- with flocked(f):
- print f.read()
RAW Paste Data