* [PATCH 0/4] Improve error reporting for registerEventHandler
@ 2015-12-31 16:42 Ed Bartosh
2015-12-31 16:42 ` [PATCH 1/4] cooker: add state.get_name method Ed Bartosh
` (3 more replies)
0 siblings, 4 replies; 10+ messages in thread
From: Ed Bartosh @ 2015-12-31 16:42 UTC (permalink / raw)
To: bitbake-devel
Hi,
This patchset includes refactoring changes for the code that deals
with registering UI event handlers. It improves error reporting
and cleans up the code a bit.
Ed Bartosh (4):
cooker: add state.get_name method
uievent: add error to registerEventHandler return
uievent: get rid of EventHandler attribute
uievent: refactor retry loop
bitbake/lib/bb/cooker.py | 8 ++++++++
bitbake/lib/bb/server/xmlrpc.py | 4 ++--
bitbake/lib/bb/ui/uievent.py | 22 +++++++++++-----------
3 files changed, 21 insertions(+), 13 deletions(-)
--
Regards,
Ed
^ permalink raw reply [flat|nested] 10+ messages in thread* [PATCH 1/4] cooker: add state.get_name method
2015-12-31 16:42 [PATCH 0/4] Improve error reporting for registerEventHandler Ed Bartosh
@ 2015-12-31 16:42 ` Ed Bartosh
2015-12-31 16:42 ` [PATCH 2/4] uievent: add error to registerEventHandler return Ed Bartosh
` (2 subsequent siblings)
3 siblings, 0 replies; 10+ messages in thread
From: Ed Bartosh @ 2015-12-31 16:42 UTC (permalink / raw)
To: bitbake-devel
Added method to convert state code into the human readable name.
It will be used in logging and error reporting.
Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
diff --git a/bitbake/lib/bb/cooker.py b/bitbake/lib/bb/cooker.py
index 4df8881..1d83226 100644
--- a/bitbake/lib/bb/cooker.py
+++ b/bitbake/lib/bb/cooker.py
@@ -67,6 +67,14 @@ class CollectionError(bb.BBHandledException):
class state:
initial, parsing, running, shutdown, forceshutdown, stopped, error = range(7)
+ @classmethod
+ def get_name(cls, code):
+ for name in dir(cls):
+ value = getattr(cls, name)
+ if type(value) == type(cls.initial) and value == code:
+ return name
+ raise ValueError("Invalid status code: %s" % code)
+
class SkippedPackage:
def __init__(self, info = None, reason = None):
--
2.1.4
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH 2/4] uievent: add error to registerEventHandler return
2015-12-31 16:42 [PATCH 0/4] Improve error reporting for registerEventHandler Ed Bartosh
2015-12-31 16:42 ` [PATCH 1/4] cooker: add state.get_name method Ed Bartosh
@ 2015-12-31 16:42 ` Ed Bartosh
2015-12-31 16:42 ` [PATCH 3/4] uievent: get rid of EventHandler attribute Ed Bartosh
2015-12-31 16:42 ` [PATCH 4/4] uievent: refactor retry loop Ed Bartosh
3 siblings, 0 replies; 10+ messages in thread
From: Ed Bartosh @ 2015-12-31 16:42 UTC (permalink / raw)
To: bitbake-devel
Current code throws Exception("Could not register UI event handler")
if event handler can't be registered. The real reason of this is that
cooker is in busy state. Error message lacks information about this.
Added error message to the return value of registerEventHandler.
Included returned error message into the log message and exception
text.
Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
diff --git a/bitbake/lib/bb/server/xmlrpc.py b/bitbake/lib/bb/server/xmlrpc.py
index b7647c1..17eb28b 100644
--- a/bitbake/lib/bb/server/xmlrpc.py
+++ b/bitbake/lib/bb/server/xmlrpc.py
@@ -97,10 +97,10 @@ class BitBakeServerCommands():
# we don't allow connections if the cooker is running
if (self.cooker.state in [bb.cooker.state.parsing, bb.cooker.state.running]):
- return None
+ return None, "Cooker is busy: %s" % bb.cooker.state.get_name(self.cooker.state)
self.event_handle = bb.event.register_UIHhandler(s, True)
- return self.event_handle
+ return self.event_handle, 'OK'
def unregisterEventHandler(self, handlerNum):
"""
diff --git a/bitbake/lib/bb/ui/uievent.py b/bitbake/lib/bb/ui/uievent.py
index 7fc50c7..80686a6 100644
--- a/bitbake/lib/bb/ui/uievent.py
+++ b/bitbake/lib/bb/ui/uievent.py
@@ -52,19 +52,21 @@ class BBUIEventQueue:
# giving up
while self.EventHandler == None and count_tries < 5:
- self.EventHandle = self.BBServer.registerEventHandler(self.host, self.port)
+ self.EventHandle, error = 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))
+ 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:
- raise Exception("Could not register UI event handler")
+ raise Exception(errmsg)
self.server = server
--
2.1.4
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH 3/4] uievent: get rid of EventHandler attribute
2015-12-31 16:42 [PATCH 0/4] Improve error reporting for registerEventHandler Ed Bartosh
2015-12-31 16:42 ` [PATCH 1/4] cooker: add state.get_name method Ed Bartosh
2015-12-31 16:42 ` [PATCH 2/4] uievent: add error to registerEventHandler return Ed Bartosh
@ 2015-12-31 16:42 ` Ed Bartosh
2015-12-31 16:42 ` [PATCH 4/4] uievent: refactor retry loop Ed Bartosh
3 siblings, 0 replies; 10+ messages in thread
From: Ed Bartosh @ 2015-12-31 16:42 UTC (permalink / raw)
To: bitbake-devel
This attribute was introduced by mistake. EventHandle is used in the
code for the same purpose.
Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
diff --git a/bitbake/lib/bb/ui/uievent.py b/bitbake/lib/bb/ui/uievent.py
index 80686a6..a900555 100644
--- a/bitbake/lib/bb/ui/uievent.py
+++ b/bitbake/lib/bb/ui/uievent.py
@@ -44,14 +44,14 @@ class BBUIEventQueue:
server.register_function( self.send_event, "event.sendpickle" )
server.socket.settimeout(1)
- self.EventHandler = None
+ 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.EventHandler == None and count_tries < 5:
+ while self.EventHandle == None and count_tries < 5:
self.EventHandle, error = self.BBServer.registerEventHandler(self.host, self.port)
if (self.EventHandle != None):
--
2.1.4
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH 4/4] uievent: refactor retry loop
2015-12-31 16:42 [PATCH 0/4] Improve error reporting for registerEventHandler Ed Bartosh
` (2 preceding siblings ...)
2015-12-31 16:42 ` [PATCH 3/4] uievent: get rid of EventHandler attribute Ed Bartosh
@ 2015-12-31 16:42 ` Ed Bartosh
2016-01-02 19:29 ` Christopher Larson
3 siblings, 1 reply; 10+ messages in thread
From: Ed Bartosh @ 2015-12-31 16:42 UTC (permalink / raw)
To: bitbake-devel
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>
diff --git a/bitbake/lib/bb/ui/uievent.py b/bitbake/lib/bb/ui/uievent.py
index a900555..70a923d 100644
--- a/bitbake/lib/bb/ui/uievent.py
+++ b/bitbake/lib/bb/ui/uievent.py
@@ -45,29 +45,27 @@ 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
+ if count_tries == 4:
+ raise Exception(errmsg)
+
import time
time.sleep(1)
-
- if self.EventHandle == None:
- raise Exception(errmsg)
-
self.server = server
self.t = threading.Thread()
--
2.1.4
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [PATCH 4/4] uievent: refactor retry loop
2015-12-31 16:42 ` [PATCH 4/4] uievent: refactor retry loop Ed Bartosh
@ 2016-01-02 19:29 ` Christopher Larson
2016-01-04 8:14 ` [PATCH v2] " Ed Bartosh
0 siblings, 1 reply; 10+ 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] 10+ messages in thread* [PATCH v2] uievent: refactor retry loop
2016-01-02 19:29 ` Christopher Larson
@ 2016-01-04 8:14 ` Ed Bartosh
2016-01-04 9:26 ` [PATCH 4/4 v3] " Ed Bartosh
0 siblings, 1 reply; 10+ messages in thread
From: Ed Bartosh @ 2016-01-04 8:14 UTC (permalink / raw)
To: bitbake-devel
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] 10+ messages in thread* [PATCH 4/4 v3] uievent: refactor retry loop
2016-01-04 8:14 ` [PATCH v2] " Ed Bartosh
@ 2016-01-04 9:26 ` Ed Bartosh
0 siblings, 0 replies; 10+ messages in thread
From: Ed Bartosh @ 2016-01-04 9:26 UTC (permalink / raw)
To: bitbake-devel
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 | 16 +++++++---------
1 file changed, 7 insertions(+), 9 deletions(-)
diff --git a/bitbake/lib/bb/ui/uievent.py b/bitbake/lib/bb/ui/uievent.py
index 19a9301..4670cdb 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))
+ 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] 10+ messages in thread
* [PATCH v2] uievent: refactor retry loop
@ 2016-01-04 8:12 Ed Bartosh
2016-01-04 8:20 ` Ed Bartosh
0 siblings, 1 reply; 10+ 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] 10+ messages in thread* Re: [PATCH v2] uievent: refactor retry loop
2016-01-04 8:12 [PATCH v2] " Ed Bartosh
@ 2016-01-04 8:20 ` Ed Bartosh
0 siblings, 0 replies; 10+ messages in thread
From: Ed Bartosh @ 2016-01-04 8:20 UTC (permalink / raw)
To: openembedded-core; +Cc: CABcZANkw_e36yhZgTVcMdVO5fm7=B4UoN-ZxjKOzNOQTvf3-1g
wrong list. please ignore.
On Mon, Jan 04, 2016 at 10:12:16AM +0200, Ed Bartosh wrote:
> 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
>
--
--
Regards,
Ed
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2016-01-04 11:23 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-12-31 16:42 [PATCH 0/4] Improve error reporting for registerEventHandler Ed Bartosh
2015-12-31 16:42 ` [PATCH 1/4] cooker: add state.get_name method Ed Bartosh
2015-12-31 16:42 ` [PATCH 2/4] uievent: add error to registerEventHandler return Ed Bartosh
2015-12-31 16:42 ` [PATCH 3/4] uievent: get rid of EventHandler attribute Ed Bartosh
2015-12-31 16:42 ` [PATCH 4/4] uievent: refactor retry loop Ed Bartosh
2016-01-02 19:29 ` Christopher Larson
2016-01-04 8:14 ` [PATCH v2] " Ed Bartosh
2016-01-04 9:26 ` [PATCH 4/4 v3] " Ed Bartosh
-- strict thread matches above, loose matches on Subject: below --
2016-01-04 8:12 [PATCH v2] " Ed Bartosh
2016-01-04 8:20 ` 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.