diff mbox series

[6/7] process: Improve client disconnect/idle sync

Message ID 20221221141543.497904-6-richard.purdie@linuxfoundation.org
State New
Headers show
Series [1/7] knotty: Ping the server/cooker periodically | expand

Commit Message

Richard Purdie Dec. 21, 2022, 2:15 p.m. UTC
When clients are disconnecting, we need to ensure things are in sync with
the idle thread. This patch is probably a little paranoid but it doesn't
really hurt to ensure things are properly in sync and nothing unexpected
will execute. A simple counter to show activity seems to easiest way to
synchronise.

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

Patch

diff --git a/lib/bb/server/process.py b/lib/bb/server/process.py
index c9984539e8..12dfb6ea19 100644
--- a/lib/bb/server/process.py
+++ b/lib/bb/server/process.py
@@ -88,6 +88,7 @@  class ProcessServer():
         self.maxuiwait = 30
         self.xmlrpc = False
 
+        self.idle_count = 1
         self.idle = None
         self._idlefuns = {}
 
@@ -178,6 +179,13 @@  class ProcessServer():
                 del self.event_writer
                 self.lastui = time.time()
                 self.cooker.command.finishAsyncDisconnect()
+
+                # Wait for the idle loop to have executed (5s max)
+                count = self.idle_count
+                start = time.time()
+                while count == self.idle_count and time.time() < (start + 5):
+                    continue
+
                 self.cooker.clientComplete()
                 self.haveui = False
             ready = select.select(fds,[],[],0)[0]
@@ -360,6 +368,11 @@  class ProcessServer():
 
     def idle_thread(self):
         while not self.quit:
+            # Show activity
+            if self.idle_count > 100000000:
+                self.idle_count = 1
+            self.idle_count = self.idle_count + 1
+
             nextsleep = 0.1
             fds = []
             for function, data in list(self._idlefuns.items()):