[PATCH 2 of 2] py3: flush ui after each message in interactive patch filtering

Yuya Nishihara yuya at tcha.org
Thu Oct 10 09:41:26 EDT 2019


On Thu, 10 Oct 2019 15:19:37 +0200, Denis Laxalde wrote:
> Yuya Nishihara a écrit :
> > I suspect that "sys.stdout.buffer" isn't line-buffered on Python 3 even
> > though "sys.stdout" is documented as such. If that's true, we'll need another
> > hack to make our stdout do the right thing.
> > 
> > https://docs.python.org/3/library/sys.html#sys.stdout
> 
> As far as I can tell, "sys.stdout.buffer" is line-buffered on python3. It
> seems to me that the problem is that we're not actually using this but
> procutil.stdout as ui._fout; and procutil happens to replace stdout
> (initially "sys.stdout.buffer") by "os.fdopen(stdout.fileno(), r'wb',
> 1)". But apparently, the buffering=1 argument is not usable for binary
> mode, according to:

Interesting. So bytes I/O doesn't support line-buffering?

>   https://docs.python.org/3/library/functions.html#open
>   https://docs.python.org/3/library/os.html#os.fdopen
> 
> I would then suggest to not replace stdout in procutil when using
> python3 (and keep sys.stdout.buffer). Would that be correct?

Maybe. The hack in procutil.py exists because there's no standard way
to change the buffering mode of the underlying FILE object. If we can
explicitly make sys.stdout.buffer line-buffered, we won't have to reopen
the stdout.


More information about the Mercurial-devel mailing list