All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] uievent: refactor retry loop
@ 2016-01-04  8:12 Ed Bartosh
  2016-01-04  8:20 ` Ed Bartosh
  0 siblings, 1 reply; 3+ messages in thread
From: Ed Bartosh @ 2016-01-04  8:12 UTC (permalink / raw)
  To: openembedded-core; +Cc: CABcZANkw_e36yhZgTVcMdVO5fm7=B4UoN-ZxjKOzNOQTvf3-1g

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

Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
---
 bitbake/lib/bb/ui/uievent.py | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/bitbake/lib/bb/ui/uievent.py b/bitbake/lib/bb/ui/uievent.py
index 19a9301..af239a3 100644
--- a/bitbake/lib/bb/ui/uievent.py
+++ b/bitbake/lib/bb/ui/uievent.py
@@ -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
-- 
2.1.4



^ permalink raw reply related	[flat|nested] 3+ messages in thread
* Re: [PATCH 4/4] uievent: refactor retry loop
@ 2016-01-02 19:29 Christopher Larson
  2016-01-04  8:14 ` [PATCH v2] " Ed Bartosh
  0 siblings, 1 reply; 3+ messages in thread
From: Christopher Larson @ 2016-01-02 19:29 UTC (permalink / raw)
  To: Ed Bartosh; +Cc: bitbake-devel@lists.openembedded.org

[-- Attachment #1: Type: text/plain, Size: 1140 bytes --]

On Thu, Dec 31, 2015 at 9:42 AM, Ed Bartosh <ed.bartosh@linux.intel.com>
wrote:

> +        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
> +            if count_tries == 4:
> +                raise Exception(errmsg)
> +
>

I'd just use the else clause of the for loop here, this is just the sort of
case it's good for. The else clause is run when the loop finished / didn't
break.

for count_tries in range(5):
    # do stuff
    if something:
        break
else:
    # didn't break
    raise Exception(errmsg)
-- 
Christopher Larson
clarson at kergoth dot com
Founder - BitBake, OpenEmbedded, OpenZaurus
Maintainer - Tslib
Senior Software Engineer, Mentor Graphics

[-- Attachment #2: Type: text/html, Size: 1990 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-01-04 10:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-01-04  8:12 [PATCH v2] uievent: refactor retry loop Ed Bartosh
2016-01-04  8:20 ` Ed Bartosh
  -- strict thread matches above, loose matches on Subject: below --
2016-01-02 19:29 [PATCH 4/4] " Christopher Larson
2016-01-04  8:14 ` [PATCH v2] " Ed Bartosh

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.