From af93779c01425fbd936184d77b89acff44ca9a78 Mon Sep 17 00:00:00 2001 From: Florian Schulze Date: Mon, 8 Jan 2018 14:58:00 +0100 Subject: [PATCH] Fix issue #727: 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. --- changelog/727.bugfix.rst | 1 + tox/session.py | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) create mode 100644 changelog/727.bugfix.rst diff --git a/changelog/727.bugfix.rst b/changelog/727.bugfix.rst new file mode 100644 index 0000000000..a4a1060105 --- /dev/null +++ b/changelog/727.bugfix.rst @@ -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. diff --git a/tox/session.py b/tox/session.py index 2754787243..a414b4feeb 100644 --- a/tox/session.py +++ b/tox/session.py @@ -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: @@ -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 @@ -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()