summaryrefslogtreecommitdiff
path: root/Lib/test
diff options
context:
space:
mode:
authorGregory P. Smith <greg@mad-scientist.com>2008-06-01 23:44:46 +0000
committerGregory P. Smith <greg@mad-scientist.com>2008-06-01 23:44:46 +0000
commitab9fbe99cc2eb3c83315d003d2f9dcc3c7708cfc (patch)
treede776c4ae1f60839524d93865a3bdec91038d8a0 /Lib/test
parentfd159a176d1d010eb033251d4fbb76ce40aa4f2f (diff)
downloadcpython-ab9fbe99cc2eb3c83315d003d2f9dcc3c7708cfc.tar.gz
Backport r62724 from trunk. Fixes issue 2791. subprocess.Popen.communicate
now closes its stdout and stderr fds as soon as it is finished with them.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_subprocess.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py
index c2db6fab20..123d4a0218 100644
--- a/Lib/test/test_subprocess.py
+++ b/Lib/test/test_subprocess.py
@@ -304,6 +304,22 @@ class ProcessTestCase(unittest.TestCase):
self.assertEqual(remove_stderr_debug_decorations(stderr),
"pineapple")
+ # This test is Linux specific for simplicity to at least have
+ # some coverage. It is not a platform specific bug.
+ if os.path.isdir('/proc/%d/fd' % os.getpid()):
+ # Test for the fd leak reported in http://bugs.python.org/issue2791.
+ def test_communicate_pipe_fd_leak(self):
+ fd_directory = '/proc/%d/fd' % os.getpid()
+ num_fds_before_popen = len(os.listdir(fd_directory))
+ p = subprocess.Popen([sys.executable, '-c', 'print()'],
+ stdout=subprocess.PIPE)
+ p.communicate()
+ num_fds_after_communicate = len(os.listdir(fd_directory))
+ del p
+ num_fds_after_destruction = len(os.listdir(fd_directory))
+ self.assertEqual(num_fds_before_popen, num_fds_after_destruction)
+ self.assertEqual(num_fds_before_popen, num_fds_after_communicate)
+
def test_communicate_returns(self):
# communicate() should return None if no redirection is active
p = subprocess.Popen([sys.executable, "-c",