Patchwork procutil: use unbuffered stdout on Windows

login
register
mail settings
Submitter Sune Foldager
Date June 25, 2018, 2:36 p.m.
Message ID <936d9ec80550309fbebd.1529937410@firefly.edlund.dk>
Download mbox | patch
Permalink /patch/32411/
State Accepted
Headers show

Comments

Sune Foldager - June 25, 2018, 2:36 p.m.
# HG changeset patch
# User Sune Foldager <cryo@cyanite.org>
# Date 1529937374 -7200
#      Mon Jun 25 16:36:14 2018 +0200
# Node ID 936d9ec80550309fbebd1c182a7d3fe6eb3e1f56
# Parent  c07424ec633c2541136a1b35dbcea1b3243dc1c1
procutil: use unbuffered stdout on Windows

Windows doesn't support line buffering, treating it as fully buffered. This
causes output of slow commands to stutter. We use unbuffered instead.
Yuya Nishihara - June 25, 2018, 2:56 p.m.
On Mon, 25 Jun 2018 16:36:50 +0200, Sune Foldager wrote:
> # HG changeset patch
> # User Sune Foldager <cryo@cyanite.org>
> # Date 1529937374 -7200
> #      Mon Jun 25 16:36:14 2018 +0200
> # Node ID 936d9ec80550309fbebd1c182a7d3fe6eb3e1f56
> # Parent  c07424ec633c2541136a1b35dbcea1b3243dc1c1
> procutil: use unbuffered stdout on Windows

Queued, thanks.
Gregory Szorc - June 25, 2018, 11:03 p.m.
On Mon, Jun 25, 2018 at 7:56 AM, Yuya Nishihara <yuya@tcha.org> wrote:

> On Mon, 25 Jun 2018 16:36:50 +0200, Sune Foldager wrote:
> > # HG changeset patch
> > # User Sune Foldager <cryo@cyanite.org>
> > # Date 1529937374 -7200
> > #      Mon Jun 25 16:36:14 2018 +0200
> > # Node ID 936d9ec80550309fbebd1c182a7d3fe6eb3e1f56
> > # Parent  c07424ec633c2541136a1b35dbcea1b3243dc1c1
> > procutil: use unbuffered stdout on Windows
>
> Queued, thanks.
>

I queued this for stable because I've seen reports of hanging commands from
users on Windows and suspect bufferering may be the root cause. If anyone
pushes back and thinks this isn't appropriate for stable, I'd understand.
It's easy enough to drop and wait a few weeks for 4.7.

Patch

diff -r c07424ec633c -r 936d9ec80550 mercurial/utils/procutil.py
--- a/mercurial/utils/procutil.py	Tue Jun 12 12:41:09 2018 -0700
+++ b/mercurial/utils/procutil.py	Mon Jun 25 16:36:14 2018 +0200
@@ -41,9 +41,13 @@ 
 
 # glibc determines buffering on first write to stdout - if we replace a TTY
 # destined stdout with a pipe destined stdout (e.g. pager), we want line
-# buffering
+# buffering (or unbuffered, on Windows)
 if isatty(stdout):
-    stdout = os.fdopen(stdout.fileno(), r'wb', 1)
+    if pycompat.iswindows:
+        # Windows doesn't support line buffering
+        stdout = os.fdopen(stdout.fileno(), r'wb', 0)
+    else:
+        stdout = os.fdopen(stdout.fileno(), r'wb', 1)
 
 if pycompat.iswindows:
     from .. import windows as platform