Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ad537f2

Browse files
committed
Issue #3210: Revert C module changes and apply patch from Hirokazu Yamamoto instead
1 parent afdeca9 commit ad537f2

2 files changed

Lines changed: 15 additions & 31 deletions

File tree

Lib/subprocess.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -886,27 +886,26 @@ def _execute_child(self, args, executable, preexec_fn, close_fds,
886886
# translate errno using _sys_errlist (or simliar), but
887887
# how can this be done from Python?
888888
raise WindowsError(*e.args)
889+
finally:
890+
# Child is launched. Close the parent's copy of those pipe
891+
# handles that only the child should have open. You need
892+
# to make sure that no handles to the write end of the
893+
# output pipe are maintained in this process or else the
894+
# pipe will not close when the child process exits and the
895+
# ReadFile will hang.
896+
if p2cread != -1:
897+
p2cread.Close()
898+
if c2pwrite != -1:
899+
c2pwrite.Close()
900+
if errwrite != -1:
901+
errwrite.Close()
889902

890903
# Retain the process handle, but close the thread handle
891904
self._child_created = True
892905
self._handle = hp
893906
self.pid = pid
894907
ht.Close()
895908

896-
# Child is launched. Close the parent's copy of those pipe
897-
# handles that only the child should have open. You need
898-
# to make sure that no handles to the write end of the
899-
# output pipe are maintained in this process or else the
900-
# pipe will not close when the child process exits and the
901-
# ReadFile will hang.
902-
if p2cread != -1:
903-
p2cread.Close()
904-
if c2pwrite != -1:
905-
c2pwrite.Close()
906-
if errwrite != -1:
907-
errwrite.Close()
908-
909-
910909
def _internal_poll(self, _deadstate=None,
911910
_WaitForSingleObject=_subprocess.WaitForSingleObject,
912911
_WAIT_OBJECT_0=_subprocess.WAIT_OBJECT_0,

PC/_subprocess.c

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,6 @@ sp_CreateProcess(PyObject* self, PyObject* args)
429429
PyObject* env_mapping;
430430
Py_UNICODE* current_directory;
431431
PyObject* startup_info;
432-
DWORD error;
433432

434433
if (! PyArg_ParseTuple(args, "ZZOOiiOZO:CreateProcess",
435434
&application_name,
@@ -479,22 +478,8 @@ sp_CreateProcess(PyObject* self, PyObject* args)
479478

480479
Py_XDECREF(environment);
481480

482-
if (! result) {
483-
error = GetLastError();
484-
if(si.hStdInput != INVALID_HANDLE_VALUE) {
485-
CloseHandle(si.hStdInput);
486-
si.hStdInput = INVALID_HANDLE_VALUE;
487-
}
488-
if(si.hStdOutput != INVALID_HANDLE_VALUE) {
489-
CloseHandle(si.hStdOutput);
490-
si.hStdOutput = INVALID_HANDLE_VALUE;
491-
}
492-
if(si.hStdError != INVALID_HANDLE_VALUE) {
493-
CloseHandle(si.hStdError);
494-
si.hStdError = INVALID_HANDLE_VALUE;
495-
}
496-
return PyErr_SetFromWindowsErr(error);
497-
}
481+
if (! result)
482+
return PyErr_SetFromWindowsErr(GetLastError());
498483

499484
return Py_BuildValue("NNii",
500485
sp_handle_new(pi.hProcess),

0 commit comments

Comments
 (0)