Browse Source

Remove dummy lock functions from lock.py

tags/nilmdb-2.0.0
Jim Paris 4 years ago
parent
commit
f93edc469c
1 changed files with 16 additions and 29 deletions
  1. +16
    -29
      nilmdb/utils/lock.py

+ 16
- 29
nilmdb/utils/lock.py View File

@@ -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)

Loading…
Cancel
Save