add pep8 check
[multicloud/framework.git] / multivimbroker / multivimbroker / pub / utils / share_lock.py
index b594c68..c79f685 100755 (executable)
@@ -15,21 +15,26 @@ import time
 
 import redis
 
-from multivimbroker.pub.config.config import REDIS_HOST, REDIS_PORT, REDIS_PASSWD
+from multivimbroker.pub.config.config import REDIS_HOST
+from multivimbroker.pub.config.config import REDIS_PORT
+from multivimbroker.pub.config.config import REDIS_PASSWD
 
 
 class SharedLock:
-    def __init__(self, lock_key, host=REDIS_HOST, port=REDIS_PORT, password=REDIS_PASSWD, db=9, lock_timeout=5 * 60):
+    def __init__(self, lock_key, host=REDIS_HOST, port=REDIS_PORT,
+                 password=REDIS_PASSWD, db=9, lock_timeout=5 * 60):
         self.lock_key = lock_key
         self.lock_timeout = lock_timeout
-        self.redis = redis.Redis(host=host, port=port, db=db, password=password)
+        self.redis = redis.Redis(host=host, port=port,
+                                 db=db, password=password)
         self.acquire_time = -1
 
     def acquire(self):
         begin = now = int(time.time())
         while (now - begin) < self.lock_timeout:
 
-            result = self.redis.setnx(self.lock_key, now + self.lock_timeout + 1)
+            result = self.redis.setnx(self.lock_key, now +
+                                      self.lock_timeout + 1)
             if result == 1 or result is True:
                 self.acquire_time = now
                 return True
@@ -42,7 +47,8 @@ class SharedLock:
             current_lock_timestamp = int(current_lock_timestamp)
 
             if now > current_lock_timestamp:
-                next_lock_timestamp = self.redis.getset(self.lock_key, now + self.lock_timeout + 1)
+                next_lock_timestamp = self.redis.getset(self.lock_key, now +
+                                                        self.lock_timeout + 1)
                 if not next_lock_timestamp:
                     time.sleep(1)
                     continue