summaryrefslogtreecommitdiff
path: root/Lib/test
diff options
context:
space:
mode:
authorCharles-Fran?ois Natali <cf.natali@gmail.com>2013-08-25 18:24:45 +0200
committerCharles-Fran?ois Natali <cf.natali@gmail.com>2013-08-25 18:24:45 +0200
commitf22548aa37d8b92fe1b1f5b08047eae7ba65754b (patch)
treef109cef255a4776e8b5cceb4dceb8e43861d4136 /Lib/test
parent88a204704c257cd09492ccdd25a17e6220362657 (diff)
downloadcpython-f22548aa37d8b92fe1b1f5b08047eae7ba65754b.tar.gz
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')
-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 0aa4d21e31..f8cd1de325 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):