install : finer graned locking for install command

This commit is contained in:
alalazo
2016-04-29 13:28:34 +02:00
committed by Todd Gamblin
parent 5988b3a222
commit 34fe51a4aa
5 changed files with 97 additions and 30 deletions

View File

@@ -28,9 +28,13 @@
import time
import socket
import llnl.util.tty as tty
__all__ = ['Lock', 'LockTransaction', 'WriteTransaction', 'ReadTransaction',
'LockError']
# Default timeout in seconds, after which locks will raise exceptions.
_default_timeout = 60
@@ -120,6 +124,7 @@ def acquire_read(self, timeout=_default_timeout):
"""
if self._reads == 0 and self._writes == 0:
tty.debug('READ LOCK : {0._file_path} [Acquiring]'.format(self))
self._lock(fcntl.LOCK_SH, timeout) # can raise LockError.
self._reads += 1
return True
@@ -139,6 +144,7 @@ def acquire_write(self, timeout=_default_timeout):
"""
if self._writes == 0:
tty.debug('WRITE LOCK : {0._file_path} [Acquiring]'.format(self))
self._lock(fcntl.LOCK_EX, timeout) # can raise LockError.
self._writes += 1
return True
@@ -159,6 +165,7 @@ def release_read(self):
assert self._reads > 0
if self._reads == 1 and self._writes == 0:
tty.debug('READ LOCK : {0._file_path} [Released]'.format(self))
self._unlock() # can raise LockError.
self._reads -= 1
return True
@@ -179,6 +186,7 @@ def release_write(self):
assert self._writes > 0
if self._writes == 1 and self._reads == 0:
tty.debug('WRITE LOCK : {0._file_path} [Released]'.format(self))
self._unlock() # can raise LockError.
self._writes -= 1
return True