Skip to content

Commit

Permalink
Fix issue tox-dev#727: The reading of command output sometimes failed…
Browse files Browse the repository at this point in the history
… with ``IOError: [Errno 0] Error`` on Windows, this was fixed by using a simpler method to update the read buffers.
  • Loading branch information
fschulze committed Jan 8, 2018
1 parent 1f328d1 commit e608604
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Cyril Roelandt
Eli Collins
Eugene Yunak
Fernando L. Pereira
Florian Schulze
Hazal Ozturk
Henk-Jaap Wagenaar
Ian Stapleton Cordasco
Expand Down
1 change: 1 addition & 0 deletions changelog/727.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The reading of command output sometimes failed with ``IOError: [Errno 0] Error`` on Windows, this was fixed by using a simpler method to update the read buffers. - by @fschulze
8 changes: 4 additions & 4 deletions tox/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def popen(self, args, cwd=None, env=None, redirect=True, returnout=False, ignore
fout.write("actionid: %s\nmsg: %s\ncmdargs: %r\n\n" % (self.id, self.msg, args))
fout.flush()
outpath = py.path.local(fout.name)
fin = outpath.open()
fin = outpath.open('rb')
fin.read() # read the header, so it won't be written to stdout
stdout = fout
elif returnout:
Expand Down Expand Up @@ -163,13 +163,12 @@ def popen(self, args, cwd=None, env=None, redirect=True, returnout=False, ignore
out = None
last_time = time.time()
while 1:
fin_pos = fin.tell()
# 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)
if '\n' in data or (time.time() - last_time) > 1:
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
Expand All @@ -181,7 +180,8 @@ def popen(self, args, cwd=None, env=None, redirect=True, returnout=False, ignore
break
else:
time.sleep(0.1)
fin.seek(fin_pos)
# the seek updates internal read buffers
fin.seek(0, 1)
fin.close()
else:
out, err = popen.communicate()
Expand Down

0 comments on commit e608604

Please sign in to comment.