From 28ce13d18e2fc4d0ad0e6f50c82fe35f613b2ab7 Mon Sep 17 00:00:00 2001 From: Bob Lantz Date: Fri, 23 Jan 2015 16:09:30 -0800 Subject: [PATCH] Fix polling in errRun It's tricky to get this right, but basically we want to read if there is something to read; if not, we want to check for EOF. --- mininet/util.py | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/mininet/util.py b/mininet/util.py index 1fb56c1..4b6e628 100644 --- a/mininet/util.py +++ b/mininet/util.py @@ -91,19 +91,27 @@ def errRun( *cmd, **kwargs ): errDone = False while not outDone or not errDone: readable = poller.poll() - for fd, _event in readable: + for fd, event in readable: f = fdtofile[ fd ] - data = f.read( 1024 ) - if echo: - output( data ) - if f == popen.stdout: - out += data - if data == '': + if event & POLLIN: + data = f.read( 1024 ) + if echo: + output( data ) + if f == popen.stdout: + out += data + if data == '': + outDone = True + elif f == popen.stderr: + err += data + if data == '': + errDone = True + elif event & POLLHUP: + if f == popen.stdout: outDone = True - elif f == popen.stderr: - err += data - if data == '': + elif f == popen.stderr: errDone = True + poller.unregister( fd ) + returncode = popen.wait() return out, err, returncode