This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import fcntl | |
from contextlib import contextmanager | |
@contextmanager | |
def flocked(fd): | |
""" Locks FD before entering the context, always releasing the lock. """ | |
try: | |
fcntl.flock(fd, fcntl.LOCK_EX) | |
yield | |
finally: |