Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #426 by writing directly to stdout buffer if possible to prevent str vs bytes issues. #739

Merged
merged 2 commits into from
Jan 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Alexandre Conrad
Allan Feldman
Andrii Soldatenko
Anthon van der Neuth
Anthony Sottile
Asmund Grammeltwedt
Barry Warsaw
Bartolome Sanchez Salado
Expand Down
1 change: 1 addition & 0 deletions changelog/426.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Write directly to stdout buffer if possible to prevent str vs bytes issues - by @asottile
11 changes: 8 additions & 3 deletions tox/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,20 +159,25 @@ def popen(self, args, cwd=None, env=None, redirect=True, returnout=False, ignore
self.report.logpopen(popen, env=env)
try:
if resultjson and not redirect:
assert popen.stderr is None # prevent deadlock
if popen.stderr is not None:
# prevent deadlock
raise ValueError("stderr must not be piped here")
# we read binary from the process and must write using a
# binary stream
buf = getattr(sys.stdout, 'buffer', sys.stdout)
out = None
last_time = time.time()
while 1:
# we have to read one byte at a time, otherwise there
# might be no output for a long time with slow tests
data = fin.read(1)
if data:
sys.stdout.write(data)
buf.write(data)
if b'\n' in data or (time.time() - last_time) > 1:
# we flush on newlines or after 1 second to
# provide quick enough feedback to the user
# when printing a dot per test
sys.stdout.flush()
buf.flush()
last_time = time.time()
elif popen.poll() is not None:
if popen.stdout is not None:
Expand Down