From f93edc469cbe6b83ffe88ac3fd407301ba3d7749 Mon Sep 17 00:00:00 2001 From: Jim Paris Date: Fri, 23 Aug 2019 16:04:29 -0400 Subject: [PATCH] Remove dummy lock functions from lock.py --- nilmdb/utils/lock.py | 45 ++++++++++++++++---------------------------- 1 file changed, 16 insertions(+), 29 deletions(-) diff --git a/nilmdb/utils/lock.py b/nilmdb/utils/lock.py index 7cc728c..1d2cae3 100644 --- a/nilmdb/utils/lock.py +++ b/nilmdb/utils/lock.py @@ -1,33 +1,20 @@ # File locking -import warnings +import fcntl +import errno -try: - import fcntl - import errno +def exclusive_lock(f): + """Acquire an exclusive lock. Returns True on successful + lock, or False on error.""" + try: + fcntl.flock(f.fileno(), fcntl.LOCK_EX | fcntl.LOCK_NB) + except IOError as e: + if e.errno in (errno.EACCES, errno.EAGAIN): + return False + else: + raise + return True - def exclusive_lock(f): - """Acquire an exclusive lock. Returns True on successful - lock, or False on error.""" - try: - fcntl.flock(f.fileno(), fcntl.LOCK_EX | fcntl.LOCK_NB) - except IOError as e: - if e.errno in (errno.EACCES, errno.EAGAIN): - return False - else: # pragma: no cover - raise - return True - - def exclusive_unlock(f): - """Release an exclusive lock.""" - fcntl.flock(f.fileno(), fcntl.LOCK_UN) - -except ImportError: # pragma: no cover - def exclusive_lock(f): - """Dummy lock function -- does not lock!""" - warnings.warn("Pretending to lock " + str(f)) - return True - - def exclusive_unlock(f): - """Release an exclusive lock.""" - return +def exclusive_unlock(f): + """Release an exclusive lock.""" + fcntl.flock(f.fileno(), fcntl.LOCK_UN)