KVM test: kvm_subprocess: use select() in read_until_output_matches()
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 <mgoldish@redhat.com>
git-svn-id: http://test.kernel.org/svn/autotest/trunk@3798 592f7852-d20e-0410-864c-8624ca9c26a4
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 @@
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 @@
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