diff options
author | Robert Yang <liezhi.yang@windriver.com> | 2018-04-03 16:19:53 +0800 |
---|---|---|
committer | Paul Eggleton <paul.eggleton@linux.intel.com> | 2018-04-24 10:12:35 +1200 |
commit | f7e63f1814234dd6f9b92bbabafb8a42319bf82c (patch) | |
tree | 535d294d4f690b4ecf10a4a73700e52f4aa75ee5 /layerindex/utils.py | |
parent | f4f2146370992fecf668ecce749b9a6c98794402 (diff) | |
download | openembedded-core-contrib-f7e63f1814234dd6f9b92bbabafb8a42319bf82c.tar.gz |
update.py: add an option --timeout for lockfile
We have an update.py running periodically in background, but we also
need to run it manually, for example, run it to update actual_branch,
the manually run usually failed because can't get lockfile, we have to
run it again and again. A timeout option helps a lot in such a case. Now
the following command can make sure we can run the command successfully:
$ update.py -b master -a actual_branch -t 2000
Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
Diffstat (limited to 'layerindex/utils.py')
-rw-r--r-- | layerindex/utils.py | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/layerindex/utils.py b/layerindex/utils.py index 08a400143e..ebcfcaf702 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) |