summaryrefslogtreecommitdiff
path: root/lib/spack/llnl/util/lock.py
diff options
context:
space:
mode:
authorTodd Gamblin <tgamblin@llnl.gov>2018-05-18 14:41:03 -0700
committerGitHub <noreply@github.com>2018-05-18 14:41:03 -0700
commit54201e3c0216656b5b933fa2e5c36b9afcb1dc4f (patch)
tree7eb5796d84a28c9fe4b556cb3e8354aab4a95f3c /lib/spack/llnl/util/lock.py
parent780cc9d72da9165470290393aeee278ad04e93de (diff)
downloadspack-54201e3c0216656b5b933fa2e5c36b9afcb1dc4f.tar.gz
spack-54201e3c0216656b5b933fa2e5c36b9afcb1dc4f.tar.bz2
spack-54201e3c0216656b5b933fa2e5c36b9afcb1dc4f.tar.xz
spack-54201e3c0216656b5b933fa2e5c36b9afcb1dc4f.zip
locks: add configuration and command-line options to enable/disable locks (#7692)
- spack.util.lock behaves the same as llnl.util.lock, but Lock._lock and Lock._unlock do nothing. - can be disabled with a control variable. - configuration options can enable/disable locking: - `locks` option in spack configuration controls whether Spack will use filesystem locks or not. - `-l` and `-L` command-line options can force-disable or force-enable locking. - Spack will check for group- and world-writability before disabling locks, and it will not allow a group- or world-writable instance to have locks disabled. - update documentation
Diffstat (limited to 'lib/spack/llnl/util/lock.py')
-rw-r--r--lib/spack/llnl/util/lock.py30
1 files changed, 19 insertions, 11 deletions
diff --git a/lib/spack/llnl/util/lock.py b/lib/spack/llnl/util/lock.py
index ed797d2ebf..0d072418cc 100644
--- a/lib/spack/llnl/util/lock.py
+++ b/lib/spack/llnl/util/lock.py
@@ -195,11 +195,13 @@ class Lock(object):
"""
if self._reads == 0 and self._writes == 0:
- tty.debug('READ LOCK: {0.path}[{0._start}:{0._length}] [Acquiring]'
- .format(self))
+ self._debug(
+ 'READ LOCK: {0.path}[{0._start}:{0._length}] [Acquiring]'
+ .format(self))
self._lock(fcntl.LOCK_SH, timeout=timeout) # can raise LockError.
- tty.debug('READ LOCK: {0.path}[{0._start}:{0._length}] [Acquired]'
- .format(self))
+ self._debug(
+ 'READ LOCK: {0.path}[{0._start}:{0._length}] [Acquired]'
+ .format(self))
self._reads += 1
return True
else:
@@ -218,12 +220,13 @@ class Lock(object):
"""
if self._writes == 0:
- tty.debug(
+ self._debug(
'WRITE LOCK: {0.path}[{0._start}:{0._length}] [Acquiring]'
.format(self))
self._lock(fcntl.LOCK_EX, timeout=timeout) # can raise LockError.
- tty.debug('WRITE LOCK: {0.path}[{0._start}:{0._length}] [Acquired]'
- .format(self))
+ self._debug(
+ 'WRITE LOCK: {0.path}[{0._start}:{0._length}] [Acquired]'
+ .format(self))
self._writes += 1
return True
else:
@@ -243,8 +246,9 @@ class Lock(object):
assert self._reads > 0
if self._reads == 1 and self._writes == 0:
- tty.debug('READ LOCK: {0.path}[{0._start}:{0._length}] [Released]'
- .format(self))
+ self._debug(
+ 'READ LOCK: {0.path}[{0._start}:{0._length}] [Released]'
+ .format(self))
self._unlock() # can raise LockError.
self._reads -= 1
return True
@@ -265,8 +269,9 @@ class Lock(object):
assert self._writes > 0
if self._writes == 1 and self._reads == 0:
- tty.debug('WRITE LOCK: {0.path}[{0._start}:{0._length}] [Released]'
- .format(self))
+ self._debug(
+ 'WRITE LOCK: {0.path}[{0._start}:{0._length}] [Released]'
+ .format(self))
self._unlock() # can raise LockError.
self._writes -= 1
return True
@@ -274,6 +279,9 @@ class Lock(object):
self._writes -= 1
return False
+ def _debug(self, *args):
+ tty.debug(*args)
+
class LockTransaction(object):
"""Simple nested transaction context manager that uses a file lock.