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_events.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_events.py')
-rw-r--r-- | Lib/asyncio/windows_events.py | 34 |
1 files changed, 29 insertions, 5 deletions
diff --git a/Lib/asyncio/windows_events.py b/Lib/asyncio/windows_events.py index 1ffac99..b70b353 100644 --- a/Lib/asyncio/windows_events.py +++ b/Lib/asyncio/windows_events.py @@ -2,21 +2,19 @@ import errno import socket +import subprocess import weakref import struct import _winapi +from . import base_subprocess from . import futures from . import proactor_events from . import selector_events from . import tasks from . import windows_utils from .log import logger - -try: - import _overlapped -except ImportError: - from . import _overlapped +from . import _overlapped __all__ = ['SelectorEventLoop', 'ProactorEventLoop', 'IocpProactor'] @@ -168,6 +166,19 @@ class ProactorEventLoop(proactor_events.BaseProactorEventLoop): def _stop_serving(self, server): server.close() + @tasks.coroutine + def _make_subprocess_transport(self, protocol, args, shell, + stdin, stdout, stderr, bufsize, + extra=None, **kwargs): + transp = _WindowsSubprocessTransport(self, protocol, args, shell, + stdin, stdout, stderr, bufsize, + extra=None, **kwargs) + yield from transp._post_init() + return transp + + def _subprocess_closed(self, transport): + pass + class IocpProactor: """Proactor implementation using IOCP.""" @@ -413,3 +424,16 @@ class IocpProactor: if self._iocp is not None: _winapi.CloseHandle(self._iocp) self._iocp = None + + +class _WindowsSubprocessTransport(base_subprocess.BaseSubprocessTransport): + + def _start(self, args, shell, stdin, stdout, stderr, bufsize, **kwargs): + self._proc = windows_utils.Popen( + args, shell=shell, stdin=stdin, stdout=stdout, stderr=stderr, + bufsize=bufsize, **kwargs) + def callback(f): + returncode = self._proc.poll() + self._process_exited(returncode) + f = self._loop._proactor.wait_for_handle(int(self._proc._handle)) + f.add_done_callback(callback) |