[virt-tools-list] [virt-manager PATCH 5/9] inspection: remove queue draining

Pino Toscano ptoscano at redhat.com
Wed Feb 22 15:42:41 UTC 2017


Now we act for each item in the queue, so there is no more need to drain
it fully before doing anything.  Thus, turn _run into a simple
get+process+done loop.
---
 virtManager/inspection.py | 22 ++++++----------------
 1 file changed, 6 insertions(+), 16 deletions(-)

diff --git a/virtManager/inspection.py b/virtManager/inspection.py
index 41163af..c86abd5 100644
--- a/virtManager/inspection.py
+++ b/virtManager/inspection.py
@@ -17,7 +17,7 @@
 # MA 02110-1301 USA.
 #
 
-from Queue import Queue, Empty
+from Queue import Queue
 from threading import Thread
 import logging
 import re
@@ -80,22 +80,12 @@ class vmmInspection(vmmGObject):
         self.timeout_add(self._wait, cb)
 
     def _run(self):
+        # Process everything on the queue.  If the queue is empty when
+        # called, block.
         while True:
-            self._process_queue()
-
-    # Process everything on the queue.  If the queue is empty when
-    # called, block.
-    def _process_queue(self):
-        first_obj = self._q.get()
-        self._process_queue_item(first_obj)
-        self._q.task_done()
-        try:
-            while True:
-                obj = self._q.get(False)
-                self._process_queue_item(obj)
-                self._q.task_done()
-        except Empty:
-            pass
+            obj = self._q.get()
+            self._process_queue_item(obj)
+            self._q.task_done()
 
     def _process_queue_item(self, obj):
         if obj[0] == "conn_added":
-- 
2.9.3




More information about the virt-tools-list mailing list