Patchwork [2,of,5,chg-tests-fix,V2] procutil: use os.fdopen(1/2) if sys.stdout/err is None

login
register
mail settings
Submitter Pulkit Goyal
Date Dec. 8, 2020, 1:42 p.m.
Message ID <f9776bf6ae3f3bb90737.1607434941@DESKTOP-STQPTJK>
Download mbox | patch
Permalink /patch/47836/
State New
Headers show

Comments

Pulkit Goyal - Dec. 8, 2020, 1:42 p.m.
# HG changeset patch
# User Pulkit Goyal <7895pulkit@gmail.com>
# Date 1607427603 -19800
#      Tue Dec 08 17:10:03 2020 +0530
# Node ID f9776bf6ae3f3bb9073792ada2e3cba544e284dd
# Parent  13496bf926221a034c890135954fdc72c895f6d7
# EXP-Topic chg-test
procutil: use os.fdopen(1/2) if sys.stdout/err is None

According to Yuya, it's better to make `procutil.stdin/err/out` always
available.

Patch

diff -r 13496bf92622 -r f9776bf6ae3f mercurial/utils/procutil.py
--- a/mercurial/utils/procutil.py	Wed Dec 02 13:55:17 2020 +0530
+++ b/mercurial/utils/procutil.py	Tue Dec 08 17:10:03 2020 +0530
@@ -127,8 +127,12 @@ 
 
     # sys.stdin can be None
     stdin = sys.stdin.buffer if sys.stdin else os.fdopen(0, 'rb')
-    stdout = _make_write_all(sys.stdout.buffer)
-    stderr = _make_write_all(sys.stderr.buffer)
+    stdout = _make_write_all(
+        sys.stdout.buffer if sys.stdout else os.fdopen(1, 'rb')
+    )
+    stderr = _make_write_all(
+        sys.stderr.buffer if sys.stderr else os.fdopne(2, 'rb')
+    )
     if pycompat.iswindows:
         # Work around Windows bugs.
         stdout = platform.winstdout(stdout)