Skip to contentSkip to conversation

uievent: refactor retry loop

PATCH Superseded Ed Bartosh 1 participant 2 messages Jan 4, 2016

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Ed Bartosh

author
#0 lore raw

PATCH v2 1/1 uievent: refactor retry loop

Replaced 'while' loop with 'for' loop.
Made the code more compact and hopefully more understandable.

---
 bitbake/lib/bb/ui/uievent.py | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)
bitbake/lib/bb/ui/uievent.py +5 -7
index 19a9301..af239a3 100644
@@ -45,27 +45,25 @@ class BBUIEventQueue:
         server.socket.settimeout(1)
 
         self.EventHandle = None
-        count_tries = 0
 
         # the event handler registration may fail here due to cooker being in invalid state
         # this is a transient situation, and we should retry a couple of times before
         # giving up
 
-        while self.EventHandle == None and count_tries < 5:
+        for count_tries in range(5):
+
             self.EventHandle, error = self.BBServer.registerEventHandler(self.host, self.port)
 
-            if (self.EventHandle != None):
+            if self.EventHandle != None:
                 break
 
             errmsg = "Could not register UI event handler. Error: %s, host %s, "
                      "port %d" % (error, self.host, self.port))
             bb.warn("%s, retry" % errmsg)
-            count_tries += 1
+
             import time
             time.sleep(1)
-
-
-        if self.EventHandle == None:
+        else:
             raise Exception(errmsg)
 
         self.server = server
Signature · 1 line
2.1.4
author
#1 lore raw

wrong list. please ignore.

Quoted 48 lines · Ed Bartosh

Replaced 'while' loop with 'for' loop.
Made the code more compact and hopefully more understandable.

---
 bitbake/lib/bb/ui/uievent.py | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)
bitbake/lib/bb/ui/uievent.py +5 -7
index 19a9301..af239a3 100644
@@ -45,27 +45,25 @@ class BBUIEventQueue:
         server.socket.settimeout(1)
 
         self.EventHandle = None
-        count_tries = 0
 
         # the event handler registration may fail here due to cooker being in invalid state
         # this is a transient situation, and we should retry a couple of times before
         # giving up
 
-        while self.EventHandle == None and count_tries < 5:
+        for count_tries in range(5):
+
             self.EventHandle, error = self.BBServer.registerEventHandler(self.host, self.port)
 
-            if (self.EventHandle != None):
+            if self.EventHandle != None:
                 break
 
             errmsg = "Could not register UI event handler. Error: %s, host %s, "
                      "port %d" % (error, self.host, self.port))
             bb.warn("%s, retry" % errmsg)
-            count_tries += 1
+
             import time
             time.sleep(1)
-
-
-        if self.EventHandle == None:
+        else:
             raise Exception(errmsg)
 
         self.server = server
Signature · 1 line
2.1.4
Signature · 3 lines
--
Regards,
Ed