[Python-checkins] r83817 - in python/branches/release31-maint: Lib/subprocess.py PC/_subprocess.c

tim.golden python-checkins at python.org
Sun Aug 8 13:18:34 CEST 2010


Author: tim.golden
Date: Sun Aug  8 13:18:34 2010
New Revision: 83817

Log:
Issue #3210: Revert C module changes and apply patch from Hirokazu Yamamoto instead

Modified:
   python/branches/release31-maint/Lib/subprocess.py
   python/branches/release31-maint/PC/_subprocess.c

Modified: python/branches/release31-maint/Lib/subprocess.py
==============================================================================
--- python/branches/release31-maint/Lib/subprocess.py	(original)
+++ python/branches/release31-maint/Lib/subprocess.py	Sun Aug  8 13:18:34 2010
@@ -862,6 +862,19 @@
                 # translate errno using _sys_errlist (or simliar), but
                 # how can this be done from Python?
                 raise WindowsError(*e.args)
+            finally:
+                # Child is launched. Close the parent's copy of those pipe
+                # handles that only the child should have open.  You need
+                # to make sure that no handles to the write end of the
+                # output pipe are maintained in this process or else the
+                # pipe will not close when the child process exits and the
+                # ReadFile will hang.
+                if p2cread is not None:
+                    p2cread.Close()
+                if c2pwrite is not None:
+                    c2pwrite.Close()
+                if errwrite is not None:
+                    errwrite.Close()
 
             # Retain the process handle, but close the thread handle
             self._child_created = True
@@ -869,20 +882,6 @@
             self.pid = pid
             ht.Close()
 
-            # Child is launched. Close the parent's copy of those pipe
-            # handles that only the child should have open.  You need
-            # to make sure that no handles to the write end of the
-            # output pipe are maintained in this process or else the
-            # pipe will not close when the child process exits and the
-            # ReadFile will hang.
-            if p2cread is not None:
-                p2cread.Close()
-            if c2pwrite is not None:
-                c2pwrite.Close()
-            if errwrite is not None:
-                errwrite.Close()
-
-
         def _internal_poll(self, _deadstate=None,
                 _WaitForSingleObject=_subprocess.WaitForSingleObject,
                 _WAIT_OBJECT_0=_subprocess.WAIT_OBJECT_0,

Modified: python/branches/release31-maint/PC/_subprocess.c
==============================================================================
--- python/branches/release31-maint/PC/_subprocess.c	(original)
+++ python/branches/release31-maint/PC/_subprocess.c	Sun Aug  8 13:18:34 2010
@@ -429,7 +429,6 @@
     PyObject* env_mapping;
     Py_UNICODE* current_directory;
     PyObject* startup_info;
-    DWORD error;
 
     if (! PyArg_ParseTuple(args, "ZZOOiiOZO:CreateProcess",
                            &application_name,
@@ -479,22 +478,8 @@
 
     Py_XDECREF(environment);
 
-    if (! result) {
-        error = GetLastError();
-        if(si.hStdInput != INVALID_HANDLE_VALUE) {
-            CloseHandle(si.hStdInput);
-            si.hStdInput = INVALID_HANDLE_VALUE;
-        }
-        if(si.hStdOutput != INVALID_HANDLE_VALUE) {
-            CloseHandle(si.hStdOutput);
-            si.hStdOutput = INVALID_HANDLE_VALUE;
-        }
-        if(si.hStdError != INVALID_HANDLE_VALUE) {
-            CloseHandle(si.hStdError);
-            si.hStdError = INVALID_HANDLE_VALUE;
-        }
-        return PyErr_SetFromWindowsErr(error);
-    }
+    if (! result)
+        return PyErr_SetFromWindowsErr(GetLastError());
 
     return Py_BuildValue("NNii",
                          sp_handle_new(pi.hProcess),


More information about the Python-checkins mailing list