Patchwork [2,of,2,chg-tests-fix,V3] procutil: don't assign stdin to None, use os.devnull instead

login
register
mail settings
Submitter Pulkit Goyal
Date Dec. 10, 2020, 9:11 a.m.
Message ID <9123fc028ed21e8aa39a.1607591505@DESKTOP-STQPTJK>
Download mbox | patch
Permalink /patch/47857/
State Accepted
Headers show

Comments

Pulkit Goyal - Dec. 10, 2020, 9:11 a.m.
# HG changeset patch
# User Pulkit Goyal <7895pulkit@gmail.com>
# Date 1607589226 -19800
#      Thu Dec 10 14:03:46 2020 +0530
# Node ID 9123fc028ed21e8aa39a353ea6ec9e102cf3dad0
# Parent  96c66ca3f189d522dd53c736919e7343c29e6116
# EXP-Topic chg-test
procutil: don't assign stdin to None, use os.devnull instead

It will be painful to take care of procutil.stdin being None everywhere.

Thanks to Yuya who recommended it.
Yuya Nishihara - Dec. 10, 2020, 10:36 a.m.
On Thu, 10 Dec 2020 14:41:45 +0530, Pulkit Goyal wrote:
> # HG changeset patch
> # User Pulkit Goyal <7895pulkit@gmail.com>
> # Date 1607589226 -19800
> #      Thu Dec 10 14:03:46 2020 +0530
> # Node ID 9123fc028ed21e8aa39a353ea6ec9e102cf3dad0
> # Parent  96c66ca3f189d522dd53c736919e7343c29e6116
> # EXP-Topic chg-test
> procutil: don't assign stdin to None, use os.devnull instead

Also queued, thanks.

> -    stdin = sys.stdin.buffer if sys.stdin else sys.stdin
> +    if sys.stdin:
> +        stdin = sys.stdin.buffer
> +    else:
> +        stdin = open(os.devnull, 'rb')
> +        os.close(stdin.fileno())

Let's see if there is a better option applicable to all of stdin/out/err.
If not, we'll have to do the same for stdout/err.

Patch

diff -r 96c66ca3f189 -r 9123fc028ed2 mercurial/utils/procutil.py
--- a/mercurial/utils/procutil.py	Thu Dec 10 13:51:56 2020 +0530
+++ b/mercurial/utils/procutil.py	Thu Dec 10 14:03:46 2020 +0530
@@ -126,7 +126,11 @@ 
     # a silly wrapper to make a bytes stream backed by a unicode one.
 
     # sys.stdin can be None
-    stdin = sys.stdin.buffer if sys.stdin else sys.stdin
+    if sys.stdin:
+        stdin = sys.stdin.buffer
+    else:
+        stdin = open(os.devnull, 'rb')
+        os.close(stdin.fileno())
     stdout = _make_write_all(sys.stdout.buffer)
     stderr = _make_write_all(sys.stderr.buffer)
     if pycompat.iswindows: