aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xlayerindex/update.py5
-rw-r--r--layerindex/utils.py14
2 files changed, 15 insertions, 4 deletions
diff --git a/layerindex/update.py b/layerindex/update.py
index f60b943cb26..c583f3dc482 100755
--- a/layerindex/update.py
+++ b/layerindex/update.py
@@ -156,6 +156,9 @@ def main():
parser.add_option("-l", "--layer",
help = "Specify layers to update (use commas to separate multiple). Default is all published layers.",
action="store", dest="layers")
+ parser.add_option("-t", "--timeout",
+ help = "Specify timeout in seconds to get layerindex.lock. Default is 30 seconds.",
+ type="int", action="store", dest="timeout", default=30)
parser.add_option("-r", "--reload",
help = "Reload recipe data instead of updating since last update",
action="store_true", dest="reload")
@@ -265,7 +268,7 @@ def main():
update.save()
try:
lockfn = os.path.join(fetchdir, "layerindex.lock")
- lockfile = utils.lock_file(lockfn)
+ lockfile = utils.lock_file(lockfn, options.timeout, logger)
if not lockfile:
logger.error("Layer index lock timeout expired")
sys.exit(1)
diff --git a/layerindex/utils.py b/layerindex/utils.py
index 08a400143e5..ebcfcaf702a 100644
--- a/layerindex/utils.py
+++ b/layerindex/utils.py
@@ -309,8 +309,10 @@ class ListHandler(logging.Handler):
return log
-def lock_file(fn):
- starttime = time.time()
+def lock_file(fn, timeout=30, logger=None):
+ start = time.time()
+ last = start
+ counter = 1
while True:
lock = open(fn, 'w')
try:
@@ -318,8 +320,14 @@ def lock_file(fn):
return lock
except IOError:
lock.close()
- if time.time() - starttime > 30:
+ current = time.time()
+ if current - start > timeout:
return None
+ # Print a message in every 5 seconds
+ if logger and (current - last > 5):
+ last = current
+ logger.info('Trying to get lock on %s (tried %s seconds) ...' % (fn, (5 * counter)))
+ counter += 1
def unlock_file(lock):
fcntl.flock(lock, fcntl.LOCK_UN)