]> granicus.if.org Git - python/commitdiff
Issue #3210: Revert C module changes and apply patch from Hirokazu Yamamoto instead
authorTim Golden <mail@timgolden.me.uk>
Sun, 8 Aug 2010 11:18:16 +0000 (11:18 +0000)
committerTim Golden <mail@timgolden.me.uk>
Sun, 8 Aug 2010 11:18:16 +0000 (11:18 +0000)
Lib/subprocess.py
PC/_subprocess.c

index f8a6342ec551f2ac074c14dd9f1c579edbff819c..ae033d47229de3140c7a282df11aa9f8a4b7ee88 100644 (file)
@@ -886,6 +886,19 @@ class Popen(object):
                 # 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 != -1:
+                    p2cread.Close()
+                if c2pwrite != -1:
+                    c2pwrite.Close()
+                if errwrite != -1:
+                    errwrite.Close()
 
             # Retain the process handle, but close the thread handle
             self._child_created = True
@@ -893,20 +906,6 @@ class Popen(object):
             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 != -1:
-                p2cread.Close()
-            if c2pwrite != -1:
-                c2pwrite.Close()
-            if errwrite != -1:
-                errwrite.Close()
-
-
         def _internal_poll(self, _deadstate=None,
                 _WaitForSingleObject=_subprocess.WaitForSingleObject,
                 _WAIT_OBJECT_0=_subprocess.WAIT_OBJECT_0,
index 2a3207b87dee0f0ab47f68d4ca6b2b2052958c45..5132a5ed005e2cf464afd297f98fdf7b1e5db440 100644 (file)
@@ -429,7 +429,6 @@ sp_CreateProcess(PyObject* self, PyObject* args)
     PyObject* env_mapping;
     Py_UNICODE* current_directory;
     PyObject* startup_info;
-    DWORD error;
 
     if (! PyArg_ParseTuple(args, "ZZOOiiOZO:CreateProcess",
                            &application_name,
@@ -479,22 +478,8 @@ sp_CreateProcess(PyObject* self, PyObject* args)
 
     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),