From 3914aa52b42d20f7ee83d742c58d5a398155cd5e Mon Sep 17 00:00:00 2001 From: Aleksander Mistewicz Date: Fri, 7 Oct 2016 17:26:24 +0200 Subject: [PATCH] Remove magic HOLDOFF number in resource_locking.py Change-Id: I56cf4cadb695bc12b5494f4fab404ab8905af733 Signed-off-by: Aleksander Mistewicz --- tct/resource_locking.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/tct/resource_locking.py b/tct/resource_locking.py index 5183411..7c94e30 100755 --- a/tct/resource_locking.py +++ b/tct/resource_locking.py @@ -111,9 +111,10 @@ class UUIDlist(object): return ret class UUIDmanager: - def __init__(self, target, inc): + def __init__(self, target, inc, holdoff): self.target = target self.inc = inc + self.holdoff = holdoff def lock(self): # go through the list of not locked uuid files and stop on the first successfully locked @@ -147,13 +148,13 @@ class UUIDmanager: return Lockfile.unlock(UUID_DIR + UUID_PREFIX + self.target) == 0 def retrylock(self): - # try to lock a target every 60s + # try to lock a target every self.holdoff seconds # returns False if there are no available targets # True otherwise while not self.lock(): if self.target_list_is_empty(): return False - time.sleep(60) + time.sleep(self.holdoff) return True def unlockfailed(self): @@ -177,7 +178,11 @@ def parse_arguments(): group.add_argument("-r", "--retrylock", action="store_true", default=False, dest="retrylock", - help="Try to lock a device until successful") + help="Try to lock a device every HOLDOFF seconds until successful") + + parser.add_argument("--holdoff", type=int, + action="store", default=60, dest="holdoff", + help="Set HOLDOFF value (default: 60)") group.add_argument("-u", "--unlock", action="store_true", default=False, dest="unlock", @@ -207,7 +212,7 @@ def main(): raise ValueError('Invalid log level: %s' % args.loglevel) logging.basicConfig(format='%(asctime)s %(message)s',level=numeric_level) logging.debug("Begin") - uuid_man = UUIDmanager(args.target, args.inc) + uuid_man = UUIDmanager(args.target, args.inc, args.holdoff) if args.lock: if not uuid_man.lock(): logging.warn("File locking unsuccessful!") -- 2.7.4