Skip to content

Commit 888a3ca

Browse files
committed
Fix vcs subprocess output capture
1 parent 3366bf0 commit 888a3ca

File tree

2 files changed

+12
-21
lines changed

2 files changed

+12
-21
lines changed

news/8876.bugfix.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fixed hanging VCS subprocess calls when the VCS outputs a large amount of data
2+
on stderr. Restored logging of VCS errors that was inadvertently removed in pip
3+
20.2.

src/pip/_internal/vcs/versioncontrol.py

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -126,26 +126,14 @@ def call_subprocess(
126126
"Error %s while executing command %s", exc, command_desc,
127127
)
128128
raise
129-
all_output = []
130-
while True:
131-
# The "line" value is a unicode string in Python 2.
132-
line = None
133-
if proc.stdout:
134-
line = console_to_str(proc.stdout.readline())
135-
if not line:
136-
break
137-
line = line.rstrip()
138-
all_output.append(line + '\n')
139-
140-
# Show the line immediately.
141-
log_subprocess(line)
142-
try:
143-
proc.wait()
144-
finally:
145-
if proc.stdout:
146-
proc.stdout.close()
147-
if proc.stderr:
148-
proc.stderr.close()
129+
out_bytes, err_bytes = proc.communicate()
130+
# log line by line to preserve pip log indenting
131+
out = console_to_str(out_bytes)
132+
for out_line in out.splitlines():
133+
log_subprocess(out_line)
134+
err = console_to_str(err_bytes)
135+
for err_line in err.splitlines():
136+
log_subprocess(err_line)
149137

150138
proc_had_error = (
151139
proc.returncode and proc.returncode not in extra_ok_returncodes
@@ -156,7 +144,7 @@ def call_subprocess(
156144
'Check the logs for full command output.'
157145
).format(proc.returncode, command_desc)
158146
raise SubProcessError(exc_msg)
159-
return ''.join(all_output)
147+
return out
160148

161149

162150
def find_path_to_setup_from_repo_root(location, repo_root):

0 commit comments

Comments
 (0)