Comments
Patch
@@ -1,6 +1,9 @@
import logging
import signal
import subprocess
+import fcntl
+import errno
+import select
logger = logging.getLogger('BitBake.Process')
@@ -70,18 +73,40 @@ def _logged_communicate(pipe, log, input):
bufsize = 512
outdata, errdata = [], []
+ rin = []
+
+ if pipe.stdout is not None:
+ fd = pipe.stdout.fileno()
+ fl = fcntl.fcntl(fd, fcntl.F_GETFL)
+ fcntl.fcntl(fd, fcntl.F_SETFL, fl | os.O_NONBLOCK)
+ rin.append(pipe.stdout)
+ if pipe.stderr is not None:
+ fd = pipe.stderr.fileno()
+ fl = fcntl.fcntl(fd, fcntl.F_GETFL)
+ fcntl.fcntl(fd, fcntl.F_SETFL, fl | os.O_NONBLOCK)
+ rin.append(pipe.stderr)
+
while pipe.poll() is None:
- if pipe.stdout is not None:
+ rlist = rin
+ try:
+ r,w,e = select.select (rlist, [], [])
+ except OSError, e:
+ if e.errno != errno.EINTR:
+ raise
+
+ if pipe.stdout in r:
data = pipe.stdout.read(bufsize)
if data is not None:
outdata.append(data)
log.write(data)
+ log.flush()
- if pipe.stderr is not None:
+ if pipe.stderr in r:
data = pipe.stderr.read(bufsize)
if data is not None:
errdata.append(data)
log.write(data)
+ log.flush()
return ''.join(outdata), ''.join(errdata)
def run(cmd, input=None, log=None, **options):