Currently read_nonblocking() is called repeatedly until a match is found.
This is fine as long as internal_timeout, the timeout parameter passed to
read_nonblocking(), is greater than zero.  If it equals zero the loop will keep
the CPU busy and stress the host.
To avoid this, use select() to wait until there's output to read from the child
process.

Signed-off-by: Michael Goldish <mgold...@redhat.com>
---
 client/tests/kvm/kvm_subprocess.py |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/client/tests/kvm/kvm_subprocess.py 
b/client/tests/kvm/kvm_subprocess.py
index 730f20e..2ac062a 100755
--- a/client/tests/kvm/kvm_subprocess.py
+++ b/client/tests/kvm/kvm_subprocess.py
@@ -848,8 +848,12 @@ class kvm_expect(kvm_tail):
         match = None
         data = ""
 
+        fd = self._get_fd("expect")
         end_time = time.time() + timeout
-        while time.time() < end_time:
+        while True:
+            r, w, x = select.select([fd], [], [],
+                                    max(0, end_time - time.time()))
+            if fd not in r: break
             # Read data from child
             newdata = self.read_nonblocking(internal_timeout)
             # Print it if necessary
@@ -868,7 +872,8 @@ class kvm_expect(kvm_tail):
                 done = True
             # Check if child has died
             if not self.is_alive():
-                logging.debug("Process terminated with status %s" % 
self.get_status())
+                logging.debug("Process terminated with status %s" %
+                              self.get_status())
                 done = True
             # Are we done?
             if done: break
-- 
1.5.4.1

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to