Merge lp:~jelmer/brz/fix-stream-buffering into lp:brz

Proposed by Jelmer Vernooij
Status: Merged
Approved by: Jelmer Vernooij
Approved revision: no longer in the source branch.
Merge reported by: The Breezy Bot
Merged at revision: not available
Proposed branch: lp:~jelmer/brz/fix-stream-buffering
Merge into: lp:brz
Diff against target: 31 lines (+11/-3)
1 file modified
breezy/ui/text.py (+11/-3)
To merge this branch: bzr merge lp:~jelmer/brz/fix-stream-buffering
Reviewer Review Type Date Requested Status
Martin Packman Approve
Review via email: mp+363233@code.launchpad.net

Commit message

Don't buffer more than a line when reading from standard input.

Description of the change

Don't buffer more than a line when reading from standard input.

Without this change, prompts will often hang.

To post a comment you must log in.
Revision history for this message
Martin Packman (gz) wrote :

Okay, lets try.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'breezy/ui/text.py'
2--- breezy/ui/text.py 2018-11-16 12:37:19 +0000
3+++ breezy/ui/text.py 2019-02-15 01:29:19 +0000
4@@ -19,6 +19,7 @@
5 from __future__ import absolute_import
6
7 import codecs
8+import io
9 import os
10 import sys
11 import warnings
12@@ -668,9 +669,16 @@
13 def _wrap_in_stream(stream, encoding=None, errors='replace'):
14 if encoding is None:
15 encoding = _get_stream_encoding(stream)
16- encoded_stream = codecs.getreader(encoding)(stream, errors=errors)
17- encoded_stream.encoding = encoding
18- return encoded_stream
19+ # Attempt to wrap using io.open if possible, since that can do
20+ # line-buffering.
21+ try:
22+ fileno = stream.fileno()
23+ except io.UnsupportedOperation:
24+ encoded_stream = codecs.getreader(encoding)(stream, errors=errors)
25+ encoded_stream.encoding = encoding
26+ return encoded_stream
27+ else:
28+ return io.open(fileno, encoding=encoding, errors=errors, mode='r', buffering=1)
29
30
31 def _wrap_out_stream(stream, encoding=None, errors='replace'):

Subscribers

People subscribed via source and target branches