<div dir="ltr"><div class="gmail_default" style="font-family:tahoma,sans-serif">Yep, something wrong with it ? </div><div class="gmail_default" style="font-family:tahoma,sans-serif"><br></div><div class="gmail_default" style="font-family:tahoma,sans-serif">

The thing is that I&#39;m replacing bb.fatal with bb.warn to get a chance for a remote controlling to intercept errors instead of having the program shutting down.</div><div class="gmail_default" style="font-family:tahoma,sans-serif">

<br></div><div class="gmail_default" style="font-family:tahoma,sans-serif">Alex</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Jun 3, 2014 at 5:38 PM, Richard Purdie <span dir="ltr">&lt;<a href="mailto:richard.purdie@linuxfoundation.org" target="_blank">richard.purdie@linuxfoundation.org</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On Tue, 2014-06-03 at 16:26 +0100, Alex DAMIAN wrote:<br>
&gt; From: Alexandru DAMIAN &lt;<a href="mailto:alexandru.damian@intel.com">alexandru.damian@intel.com</a>&gt;<br>
&gt;<br>
&gt; When we use the XMLRPC client API to connect to a bitbake server,<br>
&gt; we want to receive errors from the API instead of having the<br>
&gt; API exiting without warning.<br>
&gt;<br>
&gt; Thus the &quot;bb.fatal&quot; calls have been replaced with &quot;bb.warn&quot; calls,<br>
&gt; and we re-raise the original exception for handling by the<br>
&gt; original caller.<br>
&gt;<br>
&gt; The bitbake starting script has been modified to properly test<br>
&gt; for failures in calling the client API and handle them.<br>
&gt;<br>
&gt; Additional error handling added in the client, as to prevent<br>
&gt; fatal crashes.<br>
&gt;<br>
&gt; Signed-off-by: Alexandru DAMIAN &lt;<a href="mailto:alexandru.damian@intel.com">alexandru.damian@intel.com</a>&gt;<br>
&gt; ---<br>
&gt;  bin/bitbake             | 23 +++++++++++++----------<br>
&gt;  lib/bb/server/xmlrpc.py | 22 +++++++++++++++-------<br>
&gt;  lib/bb/ui/uievent.py    |  3 ++-<br>
&gt;  3 files changed, 30 insertions(+), 18 deletions(-)<br>
&gt;<br>
&gt; diff --git a/bin/bitbake b/bin/bitbake<br>
&gt; index fcfe043..ab881c5 100755<br>
&gt; --- a/bin/bitbake<br>
&gt; +++ b/bin/bitbake<br>
&gt; @@ -332,26 +332,29 @@ def main():<br>
&gt;          server = servermodule.BitBakeXMLRPCClient(configParams.observe_only)<br>
&gt;          server.saveConnectionDetails(configParams.remote_server)<br>
&gt;<br>
&gt; +    def _getServerConnection(server, featureset):<br>
&gt; +        try:<br>
&gt; +            server_connection = server.establishConnection(featureset)<br>
&gt; +        except Exception as e:<br>
&gt; +            bb.fatal(&quot;Could not connect to server %s: %s&quot; % (configParams.remote_server, str(e)))<br>
&gt; +        return server_connection<br>
&gt; +<br>
&gt;      if not configParams.server_only:<br>
&gt;          if configParams.status_only:<br>
&gt; -            try:<br>
&gt; -                server_connection = server.establishConnection(featureset)<br>
&gt; -            except:<br>
&gt; -                sys.exit(1)<br>
&gt; -            if not server_connection:<br>
&gt; -                sys.exit(1)<br>
&gt; +            server_connection = _getServerConnection(server, featureset)<br>
&gt;              server_connection.terminate()<br>
&gt;              sys.exit(0)<br>
&gt;<br>
&gt;          # Setup a connection to the server (cooker)<br>
&gt; -        server_connection = server.establishConnection(featureset)<br>
&gt; -        if not server_connection:<br>
&gt; +        try:<br>
&gt; +            server_connection = server.establishConnection(featureset)<br>
&gt; +        except:<br>
&gt;              if configParams.kill_server:<br>
&gt; -                bb.fatal(&quot;Server already killed&quot;)<br>
&gt; +                bb.fatal(&quot;Server already offline&quot;)<br>
&gt;              configParams.bind = configParams.remote_server<br>
&gt;              start_server(servermodule, configParams, configuration, featureset)<br>
&gt;              bb.event.ui_queue = []<br>
&gt; -            server_connection = server.establishConnection(featureset)<br>
&gt; +            server_connection = _getServerConnection(server, featureset)<br>
&gt;<br>
&gt;          # Restore the environment in case the UI needs it<br>
&gt;          for k in cleanedvars:<br>
&gt; diff --git a/lib/bb/server/xmlrpc.py b/lib/bb/server/xmlrpc.py<br>
&gt; index 6fc5543..6ec3452 100644<br>
&gt; --- a/lib/bb/server/xmlrpc.py<br>
&gt; +++ b/lib/bb/server/xmlrpc.py<br>
&gt; @@ -80,7 +80,7 @@ class BBTransport(xmlrpclib.Transport):<br>
&gt;<br>
&gt;  def _create_server(host, port, timeout = 60):<br>
&gt;      t = BBTransport(timeout)<br>
&gt; -    s = xmlrpclib.Server(&quot;http://%s:%d/&quot; % (host, port), transport=t, allow_none=True)<br>
&gt; +    s = xmlrpclib.ServerProxy(&quot;http://%s:%d/&quot; % (host, port), transport=t, allow_none=True)<br>
&gt;      return s, t<br>
&gt;<br>
&gt;  class BitBakeServerCommands():<br>
&gt; @@ -253,13 +253,18 @@ class XMLRPCServer(SimpleXMLRPCServer, BaseImplServer):<br>
&gt;              socktimeout = self.socket.gettimeout() or nextsleep<br>
&gt;              socktimeout = min(socktimeout, nextsleep)<br>
&gt;              # Mirror what BaseServer handle_request would do<br>
&gt; -            fd_sets = select.select(fds, [], [], socktimeout)<br>
&gt; -            if fd_sets[0] and self in fd_sets[0]:<br>
&gt; -                self._handle_request_noblock()<br>
&gt; +            try:<br>
&gt; +                fd_sets = select.select(fds, [], [], socktimeout)<br>
&gt; +                if fd_sets[0] and self in fd_sets[0]:<br>
&gt; +                    self._handle_request_noblock()<br>
&gt; +            except IOError:<br>
&gt; +                # we ignore interrupted calls<br>
&gt; +                pass<br>
&gt;<br>
&gt;          # Tell idle functions we&#39;re exiting<br>
&gt;          for function, data in self._idlefuns.items():<br>
&gt;              try:<br>
&gt; +                print &quot;Running idle funcs&quot;, function, data<br>
<br>
</div></div>Did you mean to leave this in?<br>
<br>
Cheers,<br>
<br>
Richard<br>
<div class="HOEnZb"><div class="h5"><br>
&gt;                  retval = function(self, data, True)<br>
&gt;              except:<br>
&gt;                  pass<br>
&gt; @@ -346,7 +351,8 @@ class BitBakeXMLRPCClient(BitBakeBaseServer):<br>
&gt;              [host, port] = self.remote.split(&quot;:&quot;)<br>
&gt;              port = int(port)<br>
&gt;          except Exception as e:<br>
&gt; -            bb.fatal(&quot;Failed to read remote definition (%s)&quot; % str(e))<br>
&gt; +            bb.warn(&quot;Failed to read remote definition (%s)&quot; % str(e))<br>
&gt; +            raise e<br>
&gt;<br>
&gt;          # We need our IP for the server connection. We get the IP<br>
&gt;          # by trying to connect with the server<br>
&gt; @@ -356,13 +362,15 @@ class BitBakeXMLRPCClient(BitBakeBaseServer):<br>
&gt;              ip = s.getsockname()[0]<br>
&gt;              s.close()<br>
&gt;          except Exception as e:<br>
&gt; -            bb.fatal(&quot;Could not create socket for %s:%s (%s)&quot; % (host, port, str(e)))<br>
&gt; +            bb.warn(&quot;Could not create socket for %s:%s (%s)&quot; % (host, port, str(e)))<br>
&gt; +            raise e<br>
&gt;          try:<br>
&gt;              self.serverImpl = XMLRPCProxyServer(host, port)<br>
&gt;              self.connection = BitBakeXMLRPCServerConnection(self.serverImpl, (ip, 0), self.observer_only, featureset)<br>
&gt;              return self.connection.connect()<br>
&gt;          except Exception as e:<br>
&gt; -            bb.fatal(&quot;Could not connect to server at %s:%s (%s)&quot; % (host, port, str(e)))<br>
&gt; +            bb.warn(&quot;Could not connect to server at %s:%s (%s)&quot; % (host, port, str(e)))<br>
&gt; +            raise e<br>
&gt;<br>
&gt;      def endSession(self):<br>
&gt;          self.connection.removeClient()<br>
&gt; diff --git a/lib/bb/ui/uievent.py b/lib/bb/ui/uievent.py<br>
&gt; index 98658f6..eb760c0 100644<br>
&gt; --- a/lib/bb/ui/uievent.py<br>
&gt; +++ b/lib/bb/ui/uievent.py<br>
&gt; @@ -47,7 +47,8 @@ class BBUIEventQueue:<br>
&gt;          self.EventHandle = self.BBServer.registerEventHandler(self.host, self.port)<br>
&gt;<br>
&gt;          if (self.EventHandle == None):<br>
&gt; -            bb.fatal(&quot;Could not register UI event handler&quot;)<br>
&gt; +            bb.warn(&quot;Could not register UI event handler %s:%d&quot; % (self.host, self.port))<br>
&gt; +            raise Exception(&quot;Could not register UI event handler&quot;)<br>
&gt;<br>
&gt;          self.server = server<br>
&gt;<br>
&gt; --<br>
&gt; 1.9.1<br>
&gt;<br>
<br>
<br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div dir="ltr">Alex Damian<div>Yocto Project<br></div><div>SSG / OTC </div></div>
</div>