mirror of
https://github.com/python/cpython.git
synced 2024-11-25 02:44:06 +08:00
Merged revisions 70137 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r70137 | hirokazu.yamamoto | 2009-03-04 07:18:14 +0900 | 1 line Issue #5179: Fixed subprocess handle leak on failure on windows. ........
This commit is contained in:
parent
5b26fb530b
commit
0c9881782b
@ -638,21 +638,13 @@ class Popen(object):
|
|||||||
c2pread, c2pwrite,
|
c2pread, c2pwrite,
|
||||||
errread, errwrite)
|
errread, errwrite)
|
||||||
|
|
||||||
# On Windows, you cannot just redirect one or two handles: You
|
|
||||||
# either have to redirect all three or none. If the subprocess
|
|
||||||
# user has only redirected one or two handles, we are
|
|
||||||
# automatically creating PIPEs for the rest. We should close
|
|
||||||
# these after the process is started. See bug #1124861.
|
|
||||||
if mswindows:
|
if mswindows:
|
||||||
if stdin is None and p2cwrite is not None:
|
if p2cwrite is not None:
|
||||||
os.close(p2cwrite)
|
p2cwrite = msvcrt.open_osfhandle(p2cwrite.Detach(), 0)
|
||||||
p2cwrite = None
|
if c2pread is not None:
|
||||||
if stdout is None and c2pread is not None:
|
c2pread = msvcrt.open_osfhandle(c2pread.Detach(), 0)
|
||||||
os.close(c2pread)
|
if errread is not None:
|
||||||
c2pread = None
|
errread = msvcrt.open_osfhandle(errread.Detach(), 0)
|
||||||
if stderr is None and errread is not None:
|
|
||||||
os.close(errread)
|
|
||||||
errread = None
|
|
||||||
|
|
||||||
if bufsize == 0:
|
if bufsize == 0:
|
||||||
bufsize = 1 # Nearly unbuffered (XXX for now)
|
bufsize = 1 # Nearly unbuffered (XXX for now)
|
||||||
@ -737,13 +729,10 @@ class Popen(object):
|
|||||||
|
|
||||||
if stdin is None:
|
if stdin is None:
|
||||||
p2cread = GetStdHandle(STD_INPUT_HANDLE)
|
p2cread = GetStdHandle(STD_INPUT_HANDLE)
|
||||||
if p2cread is not None:
|
if p2cread is None:
|
||||||
pass
|
p2cread, _ = CreatePipe(None, 0)
|
||||||
elif stdin is None or stdin == PIPE:
|
elif stdin == PIPE:
|
||||||
p2cread, p2cwrite = CreatePipe(None, 0)
|
p2cread, p2cwrite = CreatePipe(None, 0)
|
||||||
# Detach and turn into fd
|
|
||||||
p2cwrite = p2cwrite.Detach()
|
|
||||||
p2cwrite = msvcrt.open_osfhandle(p2cwrite, 0)
|
|
||||||
elif isinstance(stdin, int):
|
elif isinstance(stdin, int):
|
||||||
p2cread = msvcrt.get_osfhandle(stdin)
|
p2cread = msvcrt.get_osfhandle(stdin)
|
||||||
else:
|
else:
|
||||||
@ -753,13 +742,10 @@ class Popen(object):
|
|||||||
|
|
||||||
if stdout is None:
|
if stdout is None:
|
||||||
c2pwrite = GetStdHandle(STD_OUTPUT_HANDLE)
|
c2pwrite = GetStdHandle(STD_OUTPUT_HANDLE)
|
||||||
if c2pwrite is not None:
|
if c2pwrite is None:
|
||||||
pass
|
_, c2pwrite = CreatePipe(None, 0)
|
||||||
elif stdout is None or stdout == PIPE:
|
elif stdout == PIPE:
|
||||||
c2pread, c2pwrite = CreatePipe(None, 0)
|
c2pread, c2pwrite = CreatePipe(None, 0)
|
||||||
# Detach and turn into fd
|
|
||||||
c2pread = c2pread.Detach()
|
|
||||||
c2pread = msvcrt.open_osfhandle(c2pread, 0)
|
|
||||||
elif isinstance(stdout, int):
|
elif isinstance(stdout, int):
|
||||||
c2pwrite = msvcrt.get_osfhandle(stdout)
|
c2pwrite = msvcrt.get_osfhandle(stdout)
|
||||||
else:
|
else:
|
||||||
@ -769,13 +755,10 @@ class Popen(object):
|
|||||||
|
|
||||||
if stderr is None:
|
if stderr is None:
|
||||||
errwrite = GetStdHandle(STD_ERROR_HANDLE)
|
errwrite = GetStdHandle(STD_ERROR_HANDLE)
|
||||||
if errwrite is not None:
|
if errwrite is None:
|
||||||
pass
|
_, errwrite = CreatePipe(None, 0)
|
||||||
elif stderr is None or stderr == PIPE:
|
elif stderr == PIPE:
|
||||||
errread, errwrite = CreatePipe(None, 0)
|
errread, errwrite = CreatePipe(None, 0)
|
||||||
# Detach and turn into fd
|
|
||||||
errread = errread.Detach()
|
|
||||||
errread = msvcrt.open_osfhandle(errread, 0)
|
|
||||||
elif stderr == STDOUT:
|
elif stderr == STDOUT:
|
||||||
errwrite = c2pwrite
|
errwrite = c2pwrite
|
||||||
elif isinstance(stderr, int):
|
elif isinstance(stderr, int):
|
||||||
|
@ -181,6 +181,8 @@ Core and Builtins
|
|||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #5179: Fixed subprocess handle leak on failure on windows.
|
||||||
|
|
||||||
- PEP 372: Added collections.OrderedDict().
|
- PEP 372: Added collections.OrderedDict().
|
||||||
|
|
||||||
- The _asdict() for method for namedtuples now returns an OrderedDict().
|
- The _asdict() for method for namedtuples now returns an OrderedDict().
|
||||||
|
@ -84,7 +84,7 @@ sp_handle_detach(sp_handle_object* self, PyObject* args)
|
|||||||
|
|
||||||
handle = self->handle;
|
handle = self->handle;
|
||||||
|
|
||||||
self->handle = NULL;
|
self->handle = INVALID_HANDLE_VALUE;
|
||||||
|
|
||||||
/* note: return the current handle, as an integer */
|
/* note: return the current handle, as an integer */
|
||||||
return HANDLE_TO_PYNUM(handle);
|
return HANDLE_TO_PYNUM(handle);
|
||||||
|
Loading…
Reference in New Issue
Block a user