[Python-checkins] cpython (merge 3.4 -> default): Merge 3.4 (asyncio)

victor.stinner python-checkins at python.org
Thu Jan 15 00:06:37 CET 2015


https://hg.python.org/cpython/rev/61a045ac0006
changeset:   94145:61a045ac0006
parent:      94143:c00be209bccf
parent:      94144:463bbd862887
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Thu Jan 15 00:05:18 2015 +0100
summary:
  Merge 3.4 (asyncio)

files:
  Lib/asyncio/base_events.py                    |   7 ++-
  Lib/asyncio/base_subprocess.py                |   4 +-
  Lib/asyncio/proactor_events.py                |   1 +
  Lib/asyncio/selector_events.py                |   5 +-
  Lib/asyncio/test_utils.py                     |   1 +
  Lib/asyncio/unix_events.py                    |  14 +++++-
  Lib/asyncio/windows_utils.py                  |  10 ++--
  Lib/test/test_asyncio/test_base_events.py     |   1 +
  Lib/test/test_asyncio/test_events.py          |  22 ++++++++++
  Lib/test/test_asyncio/test_futures.py         |   1 +
  Lib/test/test_asyncio/test_selector_events.py |   1 +
  Lib/test/test_asyncio/test_unix_events.py     |   1 +
  12 files changed, 57 insertions(+), 11 deletions(-)


diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py
--- a/Lib/asyncio/base_events.py
+++ b/Lib/asyncio/base_events.py
@@ -634,7 +634,12 @@
         else:
             transport = self._make_socket_transport(sock, protocol, waiter)
 
-        yield from waiter
+        try:
+            yield from waiter
+        except Exception as exc:
+            transport.close()
+            raise
+
         return transport, protocol
 
     @coroutine
diff --git a/Lib/asyncio/base_subprocess.py b/Lib/asyncio/base_subprocess.py
--- a/Lib/asyncio/base_subprocess.py
+++ b/Lib/asyncio/base_subprocess.py
@@ -71,6 +71,8 @@
 
     def close(self):
         for proto in self._pipes.values():
+            if proto is None:
+                continue
             proto.pipe.close()
         if self._returncode is None:
             self.terminate()
@@ -119,7 +121,7 @@
             proc.kill()
         except ProcessLookupError:
             pass
-        proc.wait()
+        self._returncode = proc.wait()
 
     @coroutine
     def _post_init(self):
diff --git a/Lib/asyncio/proactor_events.py b/Lib/asyncio/proactor_events.py
--- a/Lib/asyncio/proactor_events.py
+++ b/Lib/asyncio/proactor_events.py
@@ -111,6 +111,7 @@
             if hasattr(self._sock, 'shutdown'):
                 self._sock.shutdown(socket.SHUT_RDWR)
             self._sock.close()
+            self._sock = None
             server = self._server
             if server is not None:
                 server._detach()
diff --git a/Lib/asyncio/selector_events.py b/Lib/asyncio/selector_events.py
--- a/Lib/asyncio/selector_events.py
+++ b/Lib/asyncio/selector_events.py
@@ -182,13 +182,14 @@
             else:
                 raise  # The event loop will catch, log and ignore it.
         else:
+            protocol = protocol_factory()
             if sslcontext:
                 self._make_ssl_transport(
-                    conn, protocol_factory(), sslcontext,
+                    conn, protocol, sslcontext,
                     server_side=True, extra={'peername': addr}, server=server)
             else:
                 self._make_socket_transport(
-                    conn, protocol_factory(), extra={'peername': addr},
+                    conn, protocol , extra={'peername': addr},
                     server=server)
         # It's now up to the protocol to handle the connection.
 
diff --git a/Lib/asyncio/test_utils.py b/Lib/asyncio/test_utils.py
--- a/Lib/asyncio/test_utils.py
+++ b/Lib/asyncio/test_utils.py
@@ -307,6 +307,7 @@
             self._time += advance
 
     def close(self):
+        super().close()
         if self._check_on_close:
             try:
                 self._gen.send(0)
diff --git a/Lib/asyncio/unix_events.py b/Lib/asyncio/unix_events.py
--- a/Lib/asyncio/unix_events.py
+++ b/Lib/asyncio/unix_events.py
@@ -301,7 +301,12 @@
             self._loop.call_soon(waiter._set_result_unless_cancelled, None)
 
     def __repr__(self):
-        info = [self.__class__.__name__, 'fd=%s' % self._fileno]
+        info = [self.__class__.__name__]
+        if self._pipe is None:
+            info.append('closed')
+        elif self._closing:
+            info.append('closing')
+        info.append('fd=%s' % self._fileno)
         if self._pipe is not None:
             polling = selector_events._test_selector_event(
                           self._loop._selector,
@@ -404,7 +409,12 @@
             self._loop.call_soon(waiter._set_result_unless_cancelled, None)
 
     def __repr__(self):
-        info = [self.__class__.__name__, 'fd=%s' % self._fileno]
+        info = [self.__class__.__name__]
+        if self._pipe is None:
+            info.append('closed')
+        elif self._closing:
+            info.append('closing')
+        info.append('fd=%s' % self._fileno)
         if self._pipe is not None:
             polling = selector_events._test_selector_event(
                           self._loop._selector,
diff --git a/Lib/asyncio/windows_utils.py b/Lib/asyncio/windows_utils.py
--- a/Lib/asyncio/windows_utils.py
+++ b/Lib/asyncio/windows_utils.py
@@ -7,13 +7,13 @@
 if sys.platform != 'win32':  # pragma: no cover
     raise ImportError('win32 only')
 
-import socket
+import _winapi
 import itertools
 import msvcrt
 import os
+import socket
 import subprocess
 import tempfile
-import _winapi
 
 
 __all__ = ['socketpair', 'pipe', 'Popen', 'PIPE', 'PipeHandle']
@@ -136,7 +136,7 @@
         self._handle = handle
 
     def __repr__(self):
-        if self._handle != -1:
+        if self._handle is not None:
             handle = 'handle=%r' % self._handle
         else:
             handle = 'closed'
@@ -150,9 +150,9 @@
         return self._handle
 
     def close(self, *, CloseHandle=_winapi.CloseHandle):
-        if self._handle != -1:
+        if self._handle is not None:
             CloseHandle(self._handle)
-            self._handle = -1
+            self._handle = None
 
     __del__ = close
 
diff --git a/Lib/test/test_asyncio/test_base_events.py b/Lib/test/test_asyncio/test_base_events.py
--- a/Lib/test/test_asyncio/test_base_events.py
+++ b/Lib/test/test_asyncio/test_base_events.py
@@ -409,6 +409,7 @@
     def test_run_until_complete_loop(self):
         task = asyncio.Future(loop=self.loop)
         other_loop = self.new_test_loop()
+        self.addCleanup(other_loop.close)
         self.assertRaises(ValueError,
             other_loop.run_until_complete, task)
 
diff --git a/Lib/test/test_asyncio/test_events.py b/Lib/test/test_asyncio/test_events.py
--- a/Lib/test/test_asyncio/test_events.py
+++ b/Lib/test/test_asyncio/test_events.py
@@ -25,6 +25,7 @@
 import asyncio
 from asyncio import proactor_events
 from asyncio import selector_events
+from asyncio import sslproto
 from asyncio import test_utils
 try:
     from test import support
@@ -1585,6 +1586,7 @@
         self.assertTrue(all(f.done() for f in proto.disconnects.values()))
         self.assertEqual(proto.data[1].rstrip(b'\r\n'), b'Python')
         self.assertEqual(proto.data[2], b'')
+        transp.close()
 
     def test_subprocess_exitcode(self):
         connect = self.loop.subprocess_shell(
@@ -1594,6 +1596,7 @@
         self.assertIsInstance(proto, MySubprocessProtocol)
         self.loop.run_until_complete(proto.completed)
         self.assertEqual(7, proto.returncode)
+        transp.close()
 
     def test_subprocess_close_after_finish(self):
         connect = self.loop.subprocess_shell(
@@ -1621,6 +1624,7 @@
         transp.kill()
         self.loop.run_until_complete(proto.completed)
         self.check_killed(proto.returncode)
+        transp.close()
 
     def test_subprocess_terminate(self):
         prog = os.path.join(os.path.dirname(__file__), 'echo.py')
@@ -1635,6 +1639,7 @@
         transp.terminate()
         self.loop.run_until_complete(proto.completed)
         self.check_terminated(proto.returncode)
+        transp.close()
 
     @unittest.skipIf(sys.platform == 'win32', "Don't have SIGHUP")
     def test_subprocess_send_signal(self):
@@ -1650,6 +1655,7 @@
         transp.send_signal(signal.SIGHUP)
         self.loop.run_until_complete(proto.completed)
         self.assertEqual(-signal.SIGHUP, proto.returncode)
+        transp.close()
 
     def test_subprocess_stderr(self):
         prog = os.path.join(os.path.dirname(__file__), 'echo2.py')
@@ -1784,6 +1790,22 @@
         def create_event_loop(self):
             return asyncio.ProactorEventLoop()
 
+        if not sslproto._is_sslproto_available():
+            def test_create_ssl_connection(self):
+                raise unittest.SkipTest("need python 3.5 (ssl.MemoryBIO)")
+
+            def test_create_server_ssl(self):
+                raise unittest.SkipTest("need python 3.5 (ssl.MemoryBIO)")
+
+            def test_create_server_ssl_verify_failed(self):
+                raise unittest.SkipTest("need python 3.5 (ssl.MemoryBIO)")
+
+            def test_create_server_ssl_match_failed(self):
+                raise unittest.SkipTest("need python 3.5 (ssl.MemoryBIO)")
+
+            def test_create_server_ssl_verified(self):
+                raise unittest.SkipTest("need python 3.5 (ssl.MemoryBIO)")
+
         def test_legacy_create_ssl_connection(self):
             raise unittest.SkipTest("IocpEventLoop incompatible with legacy SSL")
 
diff --git a/Lib/test/test_asyncio/test_futures.py b/Lib/test/test_asyncio/test_futures.py
--- a/Lib/test/test_asyncio/test_futures.py
+++ b/Lib/test/test_asyncio/test_futures.py
@@ -29,6 +29,7 @@
 
     def setUp(self):
         self.loop = self.new_test_loop()
+        self.addCleanup(self.loop.close)
 
     def test_initial_state(self):
         f = asyncio.Future(loop=self.loop)
diff --git a/Lib/test/test_asyncio/test_selector_events.py b/Lib/test/test_asyncio/test_selector_events.py
--- a/Lib/test/test_asyncio/test_selector_events.py
+++ b/Lib/test/test_asyncio/test_selector_events.py
@@ -1744,6 +1744,7 @@
             test_utils.MockPattern(
                 'Fatal error on transport\nprotocol:.*\ntransport:.*'),
             exc_info=(ConnectionRefusedError, MOCK_ANY, MOCK_ANY))
+        transport.close()
 
 
 if __name__ == '__main__':
diff --git a/Lib/test/test_asyncio/test_unix_events.py b/Lib/test/test_asyncio/test_unix_events.py
--- a/Lib/test/test_asyncio/test_unix_events.py
+++ b/Lib/test/test_asyncio/test_unix_events.py
@@ -598,6 +598,7 @@
         # This is a bit overspecified. :-(
         m_log.warning.assert_called_with(
             'pipe closed by peer or os.write(pipe, data) raised exception.')
+        tr.close()
 
     @mock.patch('os.write')
     def test_write_close(self, m_write):

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list