Skip to content

Commit a94f925

Browse files
committed
sys.stdout.flush() to avoid broken line.
1 parent a21598e commit a94f925

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

pep8.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1681,15 +1681,24 @@ def get_file_results(self):
16811681
'row': self.line_offset + line_number, 'col': offset + 1,
16821682
'code': code, 'text': text,
16831683
})
1684+
# stdout is block buffered when not stdout.isatty().
1685+
# When using pep8 in multiprocess, line can be broken where
1686+
# buffer boundary since other processes write to same file.
1687+
# So flush() after print() to avoid buffer boundary.
1688+
# Typical buffer size is 8192. line written safely when
1689+
# len(line) < 8192.
1690+
sys.stdout.flush()
16841691
if self._show_source:
16851692
if line_number > len(self.lines):
16861693
line = ''
16871694
else:
16881695
line = self.lines[line_number - 1]
16891696
print(line.rstrip())
16901697
print(re.sub(r'\S', ' ', line[:offset]) + '^')
1698+
sys.stdout.flush()
16911699
if self._show_pep8 and doc:
16921700
print(' ' + doc.strip())
1701+
sys.stdout.flush()
16931702
return self.file_errors
16941703

16951704

0 commit comments

Comments
 (0)