diff Lib/test/test_subprocess.py @ 63774:bb2608f73eb7 3.1

Issue #3210: Ensure stdio handles are closed if CreateProcess fails
author Tim Golden <mail@timgolden.me.uk>
date Fri, 06 Aug 2010 13:20:12 +0000
parents 5a698a152f30
children 983f110a224e
line wrap: on
line diff
--- a/Lib/test/test_subprocess.py	Fri Aug 06 09:57:49 2010 +0000
+++ b/Lib/test/test_subprocess.py	Fri Aug 06 13:20:12 2010 +0000
@@ -548,6 +548,26 @@
         output = subprocess.check_output([sys.executable, '-c', code])
         self.assert_(output.startswith(b'Hello World!'), ascii(output))
 
+    def test_handles_closed_on_exception(self):
+        # If CreateProcess exits with an error, ensure the
+        # duplicate output handles are released
+        ifhandle, ifname = self.mkstemp()
+        ofhandle, ofname = self.mkstemp()
+        efhandle, efname = self.mkstemp()
+        try:
+            subprocess.Popen (["*"], stdin=ifhandle, stdout=ofhandle,
+              stderr=efhandle)
+        except OSError:
+            os.close(ifhandle)
+            os.remove(ifname)
+            os.close(ofhandle)
+            os.remove(ofname)
+            os.close(efhandle)
+            os.remove(efname)
+        self.assertFalse(os.path.exists(ifname))
+        self.assertFalse(os.path.exists(ofname))
+        self.assertFalse(os.path.exists(efname))
+
     #
     # POSIX tests
     #