Skip to contentSkip to conversation

server/process: Make lockfile handling clearer

PATCH New Richard Purdie 1 participant 4 messages Dec 5, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/4 server/process: Make lockfile handling clearer

---
 lib/bb/server/process.py | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
lib/bb/server/process.py +6 -4
index 81617acd96..d56681c5a9 100644
@@ -239,6 +239,12 @@ class ProcessServer(multiprocessing.Process):
         while not lock:
             with bb.utils.timeout(3):
                 lock = bb.utils.lockfile(lockfile, shared=False, retry=False, block=True)
+                if lock:
+                    # We hold the lock so we can remove the file (hide stale pid data)
+                    bb.utils.remove(lockfile)
+                    bb.utils.unlockfile(lock)
+                    return
+
                 if not lock:
                     # Some systems may not have lsof available
                     procs = None
@@ -259,10 +265,6 @@ class ProcessServer(multiprocessing.Process):
                     if procs:
                         msg += ":\n%s" % str(procs)
                     print(msg)
-                    return
-        # We hold the lock so we can remove the file (hide stale pid data)
-        bb.utils.remove(lockfile)
-        bb.utils.unlockfile(lock)
 
     def idle_commands(self, delay, fds=None):
         nextsleep = delay
Signature · 1 line
2.19.1
#1 lore raw

PATCH 2/4 server/process: Handle short reads

---
 lib/bb/server/process.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
lib/bb/server/process.py +3 -3
index d56681c5a9..fd1ba47fd5 100644
@@ -407,9 +407,9 @@ class BitBakeServer(object):
             except EOFError:
                 # Trap the child exitting/closing the pipe and error out
                 r = None
-        if not r or r != "ready":
+        if not r or r[0] != "r":
             ready.close()
-            bb.error("Unable to start bitbake server")
+            bb.error("Unable to start bitbake server (%s)" % str(r))
             if os.path.exists(logfile):
                 logstart_re = re.compile(self.start_log_format % ('([0-9]+)', '([0-9-]+ [0-9:.]+)'))
                 started = False
@@ -450,7 +450,7 @@ class BitBakeServer(object):
         os.close(self.readypipe)
         writer = ConnectionWriter(self.readypipein)
         self.cooker = bb.cooker.BBCooker(self.configuration, self.featureset)
-        writer.send("ready")
+        writer.send("r")
         writer.close()
         server.cooker = self.cooker
         server.server_timeout = self.configuration.server_timeout
Signature · 1 line
2.19.1
#2 lore raw

PATCH 3/4 process: Flush key output to logs

In reply to Richard Purdie
---
 lib/bb/server/process.py | 4 ++++
 1 file changed, 4 insertions(+)
lib/bb/server/process.py +4 -0
index fd1ba47fd5..49973d6670 100644
@@ -445,6 +445,8 @@ class BitBakeServer(object):
 
     def _startServer(self):
         print(self.start_log_format % (os.getpid(), datetime.datetime.now().strftime(self.start_log_datetime_format)))
+        sys.stdout.flush()
+
         server = ProcessServer(self.bitbake_lock, self.sock, self.sockname)
         self.configuration.setServerRegIdleCallback(server.register_idle_function)
         os.close(self.readypipe)
@@ -456,6 +458,8 @@ class BitBakeServer(object):
         server.server_timeout = self.configuration.server_timeout
         server.xmlrpcinterface = self.configuration.xmlrpcinterface
         print("Started bitbake server pid %d" % os.getpid())
+        sys.stdout.flush()
+
         server.start()
 
 def connectProcessServer(sockname, featureset):
Signature · 1 line
2.19.1
#3 lore raw

PATCH 4/4 main: Don't use print() directly, use logger

In reply to Richard Purdie

Avoid failures like:

2018-12-04 03:30:56,033 - oe-selftest - INFO - ======================================================================
2018-12-04 03:30:56,033 - oe-selftest - INFO - FAIL: pkgdata.OePkgdataUtilTests.test_find_path (subunit.RemotedTestCase)
2018-12-04 03:30:56,033 - oe-selftest - INFO - ----------------------------------------------------------------------
2018-12-04 03:30:56,033 - oe-selftest - INFO - testtools.testresult.real._StringException: Traceback (most recent call last):

[...]
AssertionError: 'Previous bitbake instance shutting down?,[77 chars]xist' != 'ERROR: Unable to find any package produci[14 chars]xist'
- Previous bitbake instance shutting down?, waiting to retry...
ERROR: Unable to find any package producing path /not/exist

We need to use the logger so output is correctly handled in such cases.

---
 lib/bb/main.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/bb/main.py +1 -1
index 732a315404..7dc953da66 100755
@@ -448,7 +448,7 @@ def setup_bitbake(configParams, configuration, extrafeatures=None):
                 else:
                     logger.info("Reconnecting to bitbake server...")
                     if not os.path.exists(sockname):
-                        print("Previous bitbake instance shutting down?, waiting to retry...")
+                        logger.info("Previous bitbake instance shutting down?, waiting to retry...")
                         i = 0
                         lock = None
                         # Wait for 5s or until we can get the lock
Signature · 1 line
2.19.1