From: Tim Golden Date: Sun, 8 Aug 2010 11:17:56 +0000 (+0000) Subject: Issue #3210: Revert C module changes and apply patch from Hirokazu Yamamoto instead X-Git-Tag: v2.7.1rc1~447 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=431774f32a22a4bdfc5a239709bcba3e8d7045e9;p=python Issue #3210: Revert C module changes and apply patch from Hirokazu Yamamoto instead --- diff --git a/Lib/subprocess.py b/Lib/subprocess.py index 3cd8e908f1..395b7a3400 100644 --- a/Lib/subprocess.py +++ b/Lib/subprocess.py @@ -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, diff --git a/PC/_subprocess.c b/PC/_subprocess.c index 41a24982fe..6780382e6e 100644 --- a/PC/_subprocess.c +++ b/PC/_subprocess.c @@ -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),