Skip to content

Commit

Permalink
Fix tox-dev#426 by writing directly to stdout buffer if possible to p…
Browse files Browse the repository at this point in the history
…revent str vs bytes issues.
  • Loading branch information
fschulze committed Jan 11, 2018
1 parent 659fd14 commit fcd44e3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
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
7 changes: 5 additions & 2 deletions tox/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,19 +160,22 @@ def popen(self, args, cwd=None, env=None, redirect=True, returnout=False, ignore
try:
if resultjson and not redirect:
assert popen.stderr is None # prevent deadlock
# 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

0 comments on commit fcd44e3

Please sign in to comment.