summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_subprocess.py
diff options
context:
space:
mode:
authorCharles-François Natali <cf.natali@gmail.com>2013-08-25 16:24:45 (GMT)
committerCharles-François Natali <cf.natali@gmail.com>2013-08-25 16:24:45 (GMT)
commit249cdc39fcfb0405ccb2c952f5d8bfce77deb53d (patch)
tree7abb55a26b0ce6a800fdad7bfd4e94fab6da220f /Lib/test/test_subprocess.py
parentec8147ba5548bac5cefa41f98517e52528a6a0bd (diff)
downloadcpython-249cdc39fcfb0405ccb2c952f5d8bfce77deb53d.zip
cpython-249cdc39fcfb0405ccb2c952f5d8bfce77deb53d.tar.gz
cpython-249cdc39fcfb0405ccb2c952f5d8bfce77deb53d.tar.bz2
Issue #18763: subprocess: The file descriptors are now closed after calling the
preexec_fn callback, which may open file descriptors.
Diffstat (limited to 'Lib/test/test_subprocess.py')
-rw-r--r--Lib/test/test_subprocess.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py
index 0aa4d21..f8cd1de 100644
--- a/Lib/test/test_subprocess.py
+++ b/Lib/test/test_subprocess.py
@@ -1938,6 +1938,23 @@ class POSIXProcessTestCase(BaseTestCase):
self.assertRaises(OSError, os.waitpid, pid, 0)
self.assertNotIn(ident, [id(o) for o in subprocess._active])
+ def test_close_fds_after_preexec(self):
+ fd_status = support.findfile("fd_status.py", subdir="subprocessdata")
+
+ # this FD is used as dup2() target by preexec_fn, and should be closed
+ # in the child process
+ fd = os.dup(1)
+ self.addCleanup(os.close, fd)
+
+ p = subprocess.Popen([sys.executable, fd_status],
+ stdout=subprocess.PIPE, close_fds=True,
+ preexec_fn=lambda: os.dup2(1, fd))
+ output, ignored = p.communicate()
+
+ remaining_fds = set(map(int, output.split(b',')))
+
+ self.assertNotIn(fd, remaining_fds)
+
@unittest.skipUnless(mswindows, "Windows specific tests")
class Win32ProcessTestCase(BaseTestCase):