All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] server/process: Ensure we don't keep looping if some other server is started
@ 2020-09-05 10:29 Richard Purdie
  2020-09-05 10:29 ` [PATCH 2/2] server/process: Prefix the log data with pid/time information Richard Purdie
  0 siblings, 1 reply; 2+ messages in thread
From: Richard Purdie @ 2020-09-05 10:29 UTC (permalink / raw
  To: bitbake-devel

Showing "leftover process" messages when a new server has started and is being
used by some UI is horrible. Compare the PID data from the lockfile to
avoid this (and the ton of confusing log data it generates).

Also, move the time.sleep() call to be after the first lock attempt, which
reduces noise in the logs significantly.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
---
 lib/bb/server/process.py | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/lib/bb/server/process.py b/lib/bb/server/process.py
index f794505fd4..83c3e6b444 100644
--- a/lib/bb/server/process.py
+++ b/lib/bb/server/process.py
@@ -266,6 +266,17 @@ class ProcessServer():
         # Finally release the lockfile but warn about other processes holding it open
         lock = self.bitbake_lock
         lockfile = self.bitbake_lock_name
+
+        def get_lock_contents(lockfile):
+            try:
+                with open(lockfile, "r") as f:
+                    return f.readlines()
+            except FileNotFoundError:
+                return None
+
+        lockcontents = get_lock_contents(lockfile)
+        serverlog("Original lockfile contents: " + str(lockcontents))
+
         lock.close()
         lock = None
 
@@ -273,14 +284,22 @@ class ProcessServer():
             i = 0
             lock = None
             while not lock and i < 30:
-                time.sleep(0.1)
                 lock = bb.utils.lockfile(lockfile, shared=False, retry=False, block=False)
+                if not lock:
+                    newlockcontents = get_lock_contents(lockfile)
+                    if newlockcontents != lockcontents:
+                        # A new server was started, the lockfile contents changed, we can exit
+                        serverlog("Lockfile now contains different contents, exiting: " + str(newlockcontents))
+                        return
+                    time.sleep(0.1)
                 i += 1
             if lock:
                 # We hold the lock so we can remove the file (hide stale pid data)
                 # via unlockfile.
                 bb.utils.unlockfile(lock)
+                serverlog("Exiting as we could obtain the lock")
                 return
+
             if not lock:
                 # Some systems may not have lsof available
                 procs = None
-- 
2.25.1


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

* [PATCH 2/2] server/process: Prefix the log data with pid/time information
  2020-09-05 10:29 [PATCH 1/2] server/process: Ensure we don't keep looping if some other server is started Richard Purdie
@ 2020-09-05 10:29 ` Richard Purdie
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Purdie @ 2020-09-05 10:29 UTC (permalink / raw
  To: bitbake-devel

Knowing which process printed which messages and the timestamp of the
message is useful for debugging, so add this. Ensure the log parsing
isn't affected by using search() instead of match().

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
---
 lib/bb/server/process.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/bb/server/process.py b/lib/bb/server/process.py
index 83c3e6b444..21f95cb61e 100644
--- a/lib/bb/server/process.py
+++ b/lib/bb/server/process.py
@@ -36,7 +36,7 @@ class ProcessTimeout(SystemExit):
     pass
 
 def serverlog(msg):
-    print(msg)
+    print(str(os.getpid()) + " " +  datetime.datetime.now().strftime('%H:%M:%S.%f') + " " + msg)
     sys.stdout.flush()
 
 class ProcessServer():
@@ -480,7 +480,7 @@ class BitBakeServer(object):
                             lines.append(line)
                         else:
                             lastlines.append(line)
-                            res = logstart_re.match(line.rstrip())
+                            res = logstart_re.search(line.rstrip())
                             if res:
                                 ldatetime = datetime.datetime.strptime(res.group(2), start_log_datetime_format)
                                 if ldatetime >= startdatetime:
-- 
2.25.1


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

end of thread, other threads:[~2020-09-05 10:29 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-09-05 10:29 [PATCH 1/2] server/process: Ensure we don't keep looping if some other server is started Richard Purdie
2020-09-05 10:29 ` [PATCH 2/2] server/process: Prefix the log data with pid/time information Richard Purdie

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.