]> 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:17:56 +0000 (11:17 +0000)
committerTim Golden <mail@timgolden.me.uk>
Sun, 8 Aug 2010 11:17:56 +0000 (11:17 +0000)
Lib/subprocess.py
PC/_subprocess.c

index 3cd8e908f1bde1a792717a96e7c22a1fb77a310f..395b7a3400d4f2eb1a821e780703dc9fd348204f 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 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
@@ -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 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,
index 41a24982fe352c847bd6f8ab6dc820d580182ffe..6780382e6ea88cd3bcd2cb8610cf13c5aa1e564c 100644 (file)
@@ -425,7 +425,6 @@ sp_CreateProcess(PyObject* self, PyObject* args)
     PyObject* env_mapping;
     char* current_directory;
     PyObject* startup_info;
-    DWORD error;
 
     if (! PyArg_ParseTuple(args, "zzOOiiOzO:CreateProcess",
                            &application_name,
@@ -475,22 +474,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),