summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorINADA Naoki <inada-n@klab.com>2014-12-27 19:30:24 +0900
committerINADA Naoki <inada-n@klab.com>2014-12-27 19:30:24 +0900
commita94f9256b0a43735207ea67a18a21c67d94f2146 (patch)
treebcb462194ba49f18b1f00dbfd818558f8615aa71
parenta21598e67abeb557f85855cdc04106c7c212f09b (diff)
downloadpep8-a94f9256b0a43735207ea67a18a21c67d94f2146.tar.gz
sys.stdout.flush() to avoid broken line.
-rwxr-xr-xpep8.py9
1 files changed, 9 insertions, 0 deletions
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