[PATCH 1 of 2 V2] log: flush stdout/err for the first log entries

Yuya Nishihara yuya at tcha.org
Tue Sep 29 10:48:50 CDT 2015


On Mon, 28 Sep 2015 18:15:22 -0500, Matt Mackall wrote:
> On Sat, 2015-09-26 at 17:03 +0900, Yuya Nishihara wrote:
> > +    # XXX hack to initialize buffering mode of stdout to the default of tty
> > +    # (i.e. IOLBF) before dup2()
> > +    sys.stdout.write('\r')
> > +    sys.stdout.flush()
> 
> Hmm, this is probably the mysterious behavior that was thwarting my own
> attempts to do this. Probably a bit too hacky.

Agreed. That's the last option.

> > +    # or call setvbuf() explicitly (needs this if stdout is /dev/null)
> > +    #import _chgutil
> > +    #_chgutil.setfilebufmode(sys.stdout, _chgutil.IOLBF)
> 
> How does this work?

It just calls setvbuf(fp, NULL, _IOLBF, 0) assuming that nothing buffered
in fp. So it is platform dependent and might have problem if something already
written to fp.


More information about the Mercurial-devel mailing list