From a94f9256b0a43735207ea67a18a21c67d94f2146 Mon Sep 17 00:00:00 2001 From: INADA Naoki Date: Sat, 27 Dec 2014 19:30:24 +0900 Subject: sys.stdout.flush() to avoid broken line. --- pep8.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pep8.py b/pep8.py index 940a272..9d3b091 100755 --- a/pep8.py +++ b/pep8.py @@ -1681,6 +1681,13 @@ class StandardReport(BaseReport): 'row': self.line_offset + line_number, 'col': offset + 1, 'code': code, 'text': text, }) + # stdout is block buffered when not stdout.isatty(). + # When using pep8 in multiprocess, line can be broken where + # buffer boundary since other processes write to same file. + # So flush() after print() to avoid buffer boundary. + # Typical buffer size is 8192. line written safely when + # len(line) < 8192. + sys.stdout.flush() if self._show_source: if line_number > len(self.lines): line = '' @@ -1688,8 +1695,10 @@ class StandardReport(BaseReport): line = self.lines[line_number - 1] print(line.rstrip()) print(re.sub(r'\S', ' ', line[:offset]) + '^') + sys.stdout.flush() if self._show_pep8 and doc: print(' ' + doc.strip()) + sys.stdout.flush() return self.file_errors -- cgit v1.2.1 From cfa24ab02e24914038c55286dbb2f19d1ccf9a31 Mon Sep 17 00:00:00 2001 From: Ian Lee Date: Mon, 12 Jan 2015 23:45:03 -0800 Subject: Reduce calls to sys.stdout.flush() from 3 to 1; issue #363 --- pep8.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/pep8.py b/pep8.py index 9d3b091..77c5df0 100755 --- a/pep8.py +++ b/pep8.py @@ -1681,13 +1681,6 @@ class StandardReport(BaseReport): 'row': self.line_offset + line_number, 'col': offset + 1, 'code': code, 'text': text, }) - # stdout is block buffered when not stdout.isatty(). - # When using pep8 in multiprocess, line can be broken where - # buffer boundary since other processes write to same file. - # So flush() after print() to avoid buffer boundary. - # Typical buffer size is 8192. line written safely when - # len(line) < 8192. - sys.stdout.flush() if self._show_source: if line_number > len(self.lines): line = '' @@ -1695,10 +1688,16 @@ class StandardReport(BaseReport): line = self.lines[line_number - 1] print(line.rstrip()) print(re.sub(r'\S', ' ', line[:offset]) + '^') - sys.stdout.flush() if self._show_pep8 and doc: print(' ' + doc.strip()) - sys.stdout.flush() + + # stdout is block buffered when not stdout.isatty(). + # line can be broken where buffer boundary since other processes + # write to same file. + # flush() after print() to avoid buffer boundary. + # Typical buffer size is 8192. line written safely when + # len(line) < 8192. + sys.stdout.flush() return self.file_errors -- cgit v1.2.1 From 73b1e63e48d46ba39ed13d775e8efdb784198cf3 Mon Sep 17 00:00:00 2001 From: Ian Lee Date: Mon, 12 Jan 2015 23:51:02 -0800 Subject: Add flush method to test support PseudoFile object; issue #363 --- testsuite/support.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/testsuite/support.py b/testsuite/support.py index 5185005..6bc795d 100644 --- a/testsuite/support.py +++ b/testsuite/support.py @@ -16,6 +16,9 @@ class PseudoFile(list): def getvalue(self): return ''.join(self) + def flush(self): + pass + class TestReport(StandardReport): """Collect the results for the tests.""" -- cgit v1.2.1 From 4579585f1441dc4bb4a9b44f58b2fbe2ef3c77dd Mon Sep 17 00:00:00 2001 From: Ian Lee Date: Mon, 12 Jan 2015 23:54:55 -0800 Subject: Update changelog for issue #363 --- CHANGES.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGES.txt b/CHANGES.txt index 774a90d..4e2adc0 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -47,6 +47,9 @@ Bug fixes: * Do not skip physical checks if the newline is escaped. (Issue #319) +* Flush sys.stdout to avoid race conditions with printing. See flake8 bug: + https://gitlab.com/pycqa/flake8/issues/17 for more details. (Issue #363) + 1.5.7 (2014-05-29) ------------------ -- cgit v1.2.1