Patchwork [bitbake-devel,3/9] uievent: retry on handler registration failure

login
register
mail settings
Submitter Alexandru DAMIAN
Date June 3, 2014, 3:26 p.m.
Message ID <7b0af0cdbae865c2e0b961fae17c217b1e4ac31a.1401808899.git.alexandru.damian@intel.com>
Download mbox | patch
Permalink /patch/73141/
State New
Headers show

Comments

Alexandru DAMIAN - June 3, 2014, 3:26 p.m.
From: Alexandru DAMIAN <alexandru.damian@intel.com>

The registration of a remote UI event handler may fail
if the server cooker is currently in some certain states.
This may happen, for example, when a remote UI is started
very fast after the bitbake server is started, and the
server hadn't time to finish initial configuration parsing.

Rather than fail outright, we have the remote UI event retry
registration for five time at one-second intervals,
in the hope it will succeed.

Signed-off-by: Alexandru DAMIAN <alexandru.damian@intel.com>
---
 lib/bb/ui/uievent.py | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

Patch

diff --git a/lib/bb/ui/uievent.py b/lib/bb/ui/uievent.py
index eb760c0..c6b100c 100644
--- a/lib/bb/ui/uievent.py
+++ b/lib/bb/ui/uievent.py
@@ -44,10 +44,26 @@  class BBUIEventQueue:
         server.register_function( self.send_event, "event.sendpickle" )
         server.socket.settimeout(1)
 
-        self.EventHandle = self.BBServer.registerEventHandler(self.host, self.port)
+        self.EventHandler = None
+        count_tries = 0
 
-        if (self.EventHandle == None):
-            bb.warn("Could not register UI event handler %s:%d" % (self.host, self.port))
+        # 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.EventHandler == None and count_tries < 5:
+            self.EventHandle = self.BBServer.registerEventHandler(self.host, self.port)
+
+            if (self.EventHandle != None):
+                break
+
+            bb.warn("Could not register UI event handler %s:%d, retry" % (self.host, self.port))
+            count_tries += 1
+            import time
+            time.sleep(1)
+
+
+        if self.EventHandle == None:
             raise Exception("Could not register UI event handler")
 
         self.server = server