From d37acb166d2416f5ae142a95655666fb19966cf7 Mon Sep 17 00:00:00 2001 From: Richard Ipsum Date: Mon, 1 Dec 2014 15:23:34 +0000 Subject: Let Popen do the multiplexing --- exts/pip.find_deps | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/exts/pip.find_deps b/exts/pip.find_deps index d788143..30ef507 100755 --- a/exts/pip.find_deps +++ b/exts/pip.find_deps @@ -250,34 +250,19 @@ def find_runtime_deps(source, name, version=None): p = subprocess.Popen(['pip', 'install', '.', '--list-dependencies=%s' % tmppath], cwd=source, - stdout=subprocess.PIPE, stderr=subprocess.PIPE, + stdout=subprocess.PIPE, stderr=subprocess.STDOUT, stdin=subprocess.PIPE) # We close stdin on parent side to prevent the child from blocking # if it reads on stdin p.stdin.close() - poll = select.poll() + while True: + line = p.stdout.readline() + if line == '': + break - logging.debug('p.stdout: %s' % p.stdout) - logging.debug('p.stderr: %s' % p.stderr) - - fdmap = {p.stdout.fileno(): p.stdout, p.stderr.fileno(): p.stderr} - poll.register(p.stdout) - poll.register(p.stderr) - - # Multiplex stdout and stderr - # TODO: replace by setting stderr=stdout - while fdmap != {}: - fds = poll.poll() - - for (fd, _) in fds: - line = fdmap[fd].readline() - if line == '': - poll.unregister(fd) - del fdmap[fd] - else: - logging.debug('%s' % line.rstrip()) + logging.debug(line.rstrip()) p.wait() # even with eof on both streams, we still wait -- cgit v1.2.1