diff options
author | Guido van Rossum <guido@dropbox.com> | 2013-10-30 21:52:03 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@dropbox.com> | 2013-10-30 21:52:03 (GMT) |
commit | 5969128a865db887a8a723acc46d5ebd720ebfe8 (patch) | |
tree | 1193fcefd2ff8e5ada11d2fd507deeab8b5826ac /Lib/asyncio/windows_utils.py | |
parent | 90fb914b4b90f74a9ab4c12d2a3aa2fa2090f3c7 (diff) | |
download | cpython-5969128a865db887a8a723acc46d5ebd720ebfe8.zip cpython-5969128a865db887a8a723acc46d5ebd720ebfe8.tar.gz cpython-5969128a865db887a8a723acc46d5ebd720ebfe8.tar.bz2 |
asyncio: Add support for running subprocesses on Windows with the IOCP event loop (Richard Oudkerk).
Diffstat (limited to 'Lib/asyncio/windows_utils.py')
-rw-r--r-- | Lib/asyncio/windows_utils.py | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/Lib/asyncio/windows_utils.py b/Lib/asyncio/windows_utils.py index 04b43e9..2fc3f7a 100644 --- a/Lib/asyncio/windows_utils.py +++ b/Lib/asyncio/windows_utils.py @@ -24,6 +24,7 @@ __all__ = ['socketpair', 'pipe', 'Popen', 'PIPE', 'PipeHandle'] BUFSIZE = 8192 PIPE = subprocess.PIPE +STDOUT = subprocess.STDOUT _mmap_counter = itertools.count() # @@ -146,24 +147,34 @@ class Popen(subprocess.Popen): The stdin, stdout, stderr are None or instances of PipeHandle. """ def __init__(self, args, stdin=None, stdout=None, stderr=None, **kwds): + assert not kwds.get('universal_newlines') + assert kwds.get('bufsize', 0) == 0 stdin_rfd = stdout_wfd = stderr_wfd = None stdin_wh = stdout_rh = stderr_rh = None if stdin == PIPE: - stdin_rh, stdin_wh = pipe(overlapped=(False, True)) + stdin_rh, stdin_wh = pipe(overlapped=(False, True), duplex=True) stdin_rfd = msvcrt.open_osfhandle(stdin_rh, os.O_RDONLY) + else: + stdin_rfd = stdin if stdout == PIPE: stdout_rh, stdout_wh = pipe(overlapped=(True, False)) stdout_wfd = msvcrt.open_osfhandle(stdout_wh, 0) + else: + stdout_wfd = stdout if stderr == PIPE: stderr_rh, stderr_wh = pipe(overlapped=(True, False)) stderr_wfd = msvcrt.open_osfhandle(stderr_wh, 0) + elif stderr == STDOUT: + stderr_wfd = stdout_wfd + else: + stderr_wfd = stderr try: - super().__init__(args, bufsize=0, universal_newlines=False, - stdin=stdin_rfd, stdout=stdout_wfd, + super().__init__(args, stdin=stdin_rfd, stdout=stdout_wfd, stderr=stderr_wfd, **kwds) except: for h in (stdin_wh, stdout_rh, stderr_rh): - _winapi.CloseHandle(h) + if h is not None: + _winapi.CloseHandle(h) raise else: if stdin_wh is not None: |