diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2014-01-10 23:03:21 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2014-01-10 23:03:21 (GMT) |
commit | 7de2646cdf70fda17fffd369fa7c1784afc1ab00 (patch) | |
tree | 8f733cd0aa7c401122759941c526dadd7bb8bbf7 /Lib/asyncio/windows_events.py | |
parent | c8935fe8608b5227ccbc944846d2d0468ab3865f (diff) | |
download | cpython-7de2646cdf70fda17fffd369fa7c1784afc1ab00.zip cpython-7de2646cdf70fda17fffd369fa7c1784afc1ab00.tar.gz cpython-7de2646cdf70fda17fffd369fa7c1784afc1ab00.tar.bz2 |
Cleanup properly proactor event loop
* store the "self reading" future when the "self pipe" is closed (when the
event loop is closed)
* store "accept" futures to cancel them when we stop serving
* close the "accept socket" if the "accept future" is cancelled
Fix many warnings which can be seen when unit tests are run in verbose mode.
Diffstat (limited to 'Lib/asyncio/windows_events.py')
-rw-r--r-- | Lib/asyncio/windows_events.py | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/Lib/asyncio/windows_events.py b/Lib/asyncio/windows_events.py index b2ed241..2e9ec69 100644 --- a/Lib/asyncio/windows_events.py +++ b/Lib/asyncio/windows_events.py @@ -168,9 +168,6 @@ class ProactorEventLoop(proactor_events.BaseProactorEventLoop): self.call_soon(loop) return [server] - def _stop_serving(self, server): - server.close() - @tasks.coroutine def _make_subprocess_transport(self, protocol, args, shell, stdin, stdout, stderr, bufsize, @@ -260,7 +257,19 @@ class IocpProactor: conn.settimeout(listener.gettimeout()) return conn, conn.getpeername() - return self._register(ov, listener, finish_accept) + @tasks.coroutine + def accept_coro(future, conn): + # Coroutine closing the accept socket if the future is cancelled + try: + yield from future + except futures.CancelledError: + conn.close() + raise + + future = self._register(ov, listener, finish_accept) + coro = accept_coro(future, conn) + tasks.async(coro, loop=self._loop) + return future def connect(self, conn, address): self._register_with_iocp(conn) |