Use flock locks for storage locking

These locks are compatible with the command line utility flock,
which comes preinstalled with most Linux distributions.
This commit is contained in:
Unrud 2016-08-04 06:15:05 +02:00
parent b71664b322
commit 8ce6d1af30

View File

@ -648,7 +648,7 @@ class Collection(BaseCollection):
elif os.name == "posix": elif os.name == "posix":
_cmd = fcntl.LOCK_EX if mode == "w" else fcntl.LOCK_SH _cmd = fcntl.LOCK_EX if mode == "w" else fcntl.LOCK_SH
try: try:
fcntl.lockf(cls._lock_file.fileno(), _cmd) fcntl.flock(cls._lock_file.fileno(), _cmd)
except OSError: except OSError:
cls.logger.debug("Locking not supported") cls.logger.debug("Locking not supported")
cls._lock_file_locked = True cls._lock_file_locked = True
@ -668,7 +668,7 @@ class Collection(BaseCollection):
cls.logger.debug("Unlocking not supported") cls.logger.debug("Unlocking not supported")
elif os.name == "posix": elif os.name == "posix":
try: try:
fcntl.lockf(cls._lock_file.fileno(), fcntl.LOCK_UN) fcntl.flock(cls._lock_file.fileno(), fcntl.LOCK_UN)
except OSError: except OSError:
cls.logger.debug("Unlocking not supported") cls.logger.debug("Unlocking not supported")
cls._lock_file_locked = False cls._lock_file_locked = False