bpo-32270: Don't close stdin/out/err in pass_fds (GH-6242) · python/cpython@ce34410 (original) (raw)
`@@ -2529,6 +2529,36 @@ def test_pass_fds_inheritable(self):
`
2529
2529
`self.assertEqual(os.get_inheritable(inheritable), True)
`
2530
2530
`self.assertEqual(os.get_inheritable(non_inheritable), False)
`
2531
2531
``
``
2532
+
``
2533
`+
bpo-32270: Ensure that descriptors specified in pass_fds
`
``
2534
`+
are inherited even if they are used in redirections.
`
``
2535
`+
Contributed by @izbyshev.
`
``
2536
`+
def test_pass_fds_redirected(self):
`
``
2537
`+
"""Regression test for https://bugs.python.org/issue32270."""
`
``
2538
`+
fd_status = support.findfile("fd_status.py", subdir="subprocessdata")
`
``
2539
`+
pass_fds = []
`
``
2540
`+
for _ in range(2):
`
``
2541
`+
fd = os.open(os.devnull, os.O_RDWR)
`
``
2542
`+
self.addCleanup(os.close, fd)
`
``
2543
`+
pass_fds.append(fd)
`
``
2544
+
``
2545
`+
stdout_r, stdout_w = os.pipe()
`
``
2546
`+
self.addCleanup(os.close, stdout_r)
`
``
2547
`+
self.addCleanup(os.close, stdout_w)
`
``
2548
`+
pass_fds.insert(1, stdout_w)
`
``
2549
+
``
2550
`+
with subprocess.Popen([sys.executable, fd_status],
`
``
2551
`+
stdin=pass_fds[0],
`
``
2552
`+
stdout=pass_fds[1],
`
``
2553
`+
stderr=pass_fds[2],
`
``
2554
`+
close_fds=True,
`
``
2555
`+
pass_fds=pass_fds):
`
``
2556
`+
output = os.read(stdout_r, 1024)
`
``
2557
`+
fds = {int(num) for num in output.split(b',')}
`
``
2558
+
``
2559
`+
self.assertEqual(fds, {0, 1, 2} | frozenset(pass_fds), f"output={output!a}")
`
``
2560
+
``
2561
+
2532
2562
`def test_stdout_stdin_are_single_inout_fd(self):
`
2533
2563
`with io.open(os.devnull, "r+") as inout:
`
2534
2564
`p = subprocess.Popen([sys.executable, "-c", "import sys; sys.exit(0)"],
`