diff options
author | Richard Ipsum <richard.ipsum@codethink.co.uk> | 2014-12-01 15:28:35 +0000 |
---|---|---|
committer | Richard Ipsum <richard.ipsum@codethink.co.uk> | 2014-12-01 15:28:35 +0000 |
commit | f491083870a5d8aad426f8d0b9b52e832e13788d (patch) | |
tree | 4ac96c3c47be4e5310d4ddb93757ff23289d4fd4 | |
parent | d37acb166d2416f5ae142a95655666fb19966cf7 (diff) | |
download | import-f491083870a5d8aad426f8d0b9b52e832e13788d.tar.gz |
Let Popen handle multiplexing
-rwxr-xr-x | exts/pip.to_lorry | 24 |
1 files changed, 6 insertions, 18 deletions
diff --git a/exts/pip.to_lorry b/exts/pip.to_lorry index d537851..1027459 100755 --- a/exts/pip.to_lorry +++ b/exts/pip.to_lorry @@ -50,31 +50,19 @@ def find_repo_type(url): tempdir = tempfile.mkdtemp() p = subprocess.Popen([vcs, vcs_command, url], stdout=subprocess.PIPE, - stderr=subprocess.PIPE, stdin=subprocess.PIPE, + stderr=subprocess.STDOUT, stdin=subprocess.PIPE, cwd=tempdir) # 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 - 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 this by setting stderr=stdout - while fdmap != {}: - fds = poll.poll() - - for (fd, _) in fds: - line = fdmap[fd].readline().rstrip() - if line == '': - poll.unregister(fd) - del fdmap[fd] - else: - logging.debug('%s' % line) + logging.debug(line.rstrip()) p.wait() # even with eof on both streams, we still wait |