socket type :py:data:`~socket.SOCK_STREAM`. *protocol_factory* must be a
callable returning a :ref:`protocol <asyncio-protocol>` instance.
- This method is a :ref:`coroutine <coroutine>` which will try to
- establish the connection in the background. When successful, the
- coroutine returns a ``(transport, protocol)`` pair.
+ This method will try to establish the connection in the background.
+ When successful, it returns a ``(transport, protocol)`` pair.
The chronological synopsis of the underlying operation is as follows:
:py:data:`~socket.SOCK_DGRAM`. *protocol_factory* must be a
callable returning a :ref:`protocol <asyncio-protocol>` instance.
- This method is a :ref:`coroutine <coroutine>` which will try to
- establish the connection in the background. When successful, the
- coroutine returns a ``(transport, protocol)`` pair.
+ This method will try to establish the connection in the background.
+ When successful, the it returns a ``(transport, protocol)`` pair.
Options changing how the connection is created:
family is used to communicate between processes on the same machine
efficiently.
- This method is a :ref:`coroutine <coroutine>` which will try to
- establish the connection in the background. When successful, the
- coroutine returns a ``(transport, protocol)`` pair.
+ This method will try to establish the connection in the background.
+ When successful, the it returns a ``(transport, protocol)`` pair.
*path* is the name of a UNIX domain socket, and is required unless a *sock*
parameter is specified. Abstract UNIX sockets, :class:`str`,
set this flag when being created. This option is not supported on
Windows.
- This method is a :ref:`coroutine <coroutine>`.
-
.. versionchanged:: 3.5
On Windows with :class:`ProactorEventLoop`, SSL/TLS is now supported.
parameter is specified. Abstract UNIX sockets, :class:`str`,
:class:`bytes`, and :class:`~pathlib.Path` paths are supported.
- This method is a :ref:`coroutine <coroutine>`.
-
Availability: UNIX.
.. versionchanged:: 3.7
* *ssl* can be set to an :class:`~ssl.SSLContext` to enable SSL over the
accepted connections.
- This method is a :ref:`coroutine <coroutine>`. When completed, the
- coroutine returns a ``(transport, protocol)`` pair.
+ When completed it returns a ``(transport, protocol)`` pair.
.. versionadded:: 3.5.3
With :class:`SelectorEventLoop` event loop, the socket *sock* must be
non-blocking.
- This method is a :ref:`coroutine <coroutine>`.
+ .. versionchanged:: 3.7
+ Even though the method was always documented as a coroutine
+ method, before Python 3.7 it returned a :class:`Future`.
+ Since Python 3.7, this is an ``async def`` method.
.. coroutinemethod:: AbstractEventLoop.sock_recv_into(sock, buf)
With :class:`SelectorEventLoop` event loop, the socket *sock* must be
non-blocking.
- This method is a :ref:`coroutine <coroutine>`.
-
.. versionadded:: 3.7
.. coroutinemethod:: AbstractEventLoop.sock_sendall(sock, data)
With :class:`SelectorEventLoop` event loop, the socket *sock* must be
non-blocking.
- This method is a :ref:`coroutine <coroutine>`.
+ .. versionchanged:: 3.7
+ Even though the method was always documented as a coroutine
+ method, before Python 3.7 it returned an :class:`Future`.
+ Since Python 3.7, this is an ``async def`` method.
.. coroutinemethod:: AbstractEventLoop.sock_connect(sock, address)
With :class:`SelectorEventLoop` event loop, the socket *sock* must be
non-blocking.
- This method is a :ref:`coroutine <coroutine>`.
-
.. versionchanged:: 3.5.2
``address`` no longer needs to be resolved. ``sock_connect``
will try to check if the *address* is already resolved by calling
The socket *sock* must be non-blocking.
- This method is a :ref:`coroutine <coroutine>`.
+ .. versionchanged:: 3.7
+ Even though the method was always documented as a coroutine
+ method, before Python 3.7 it returned a :class:`Future`.
+ Since Python 3.7, this is an ``async def`` method.
.. seealso::
With :class:`SelectorEventLoop` event loop, the *pipe* is set to
non-blocking mode.
- This method is a :ref:`coroutine <coroutine>`.
-
.. coroutinemethod:: AbstractEventLoop.connect_write_pipe(protocol_factory, pipe)
Register write pipe in eventloop.
With :class:`SelectorEventLoop` event loop, the *pipe* is set to
non-blocking mode.
- This method is a :ref:`coroutine <coroutine>`.
-
.. seealso::
The :meth:`AbstractEventLoop.subprocess_exec` and
:ref:`Use functools.partial to pass keywords to the *func*
<asyncio-pass-keywords>`.
- This method is a :ref:`coroutine <coroutine>`.
-
.. versionchanged:: 3.5.3
:meth:`BaseEventLoop.run_in_executor` no longer configures the
``max_workers`` of the thread pool executor it creates, instead
(:class:`~concurrent.futures.ThreadPoolExecutor`) to set the
default.
+ .. versionchanged:: 3.7
+ Even though the method was always documented as a coroutine
+ method, before Python 3.7 it returned a :class:`Future`.
+ Since Python 3.7, this is an ``async def`` method.
+
.. method:: AbstractEventLoop.set_default_executor(executor)
Set the default executor used by :meth:`run_in_executor`.
Wait until the :meth:`close` method completes.
- This method is a :ref:`coroutine <coroutine>`.
-
.. attribute:: sockets
List of :class:`socket.socket` objects the server is listening to, or
return None
-def _ensure_resolved(address, *, family=0, type=socket.SOCK_STREAM, proto=0,
- flags=0, loop):
- host, port = address[:2]
- info = _ipaddr_info(host, port, family, type, proto)
- if info is not None:
- # "host" is already a resolved IP.
- fut = loop.create_future()
- fut.set_result([info])
- return fut
- else:
- return loop.getaddrinfo(host, port, family=family, type=type,
- proto=proto, flags=flags)
-
-
def _run_until_complete_cb(fut):
exc = fut._exception
if isinstance(exc, BaseException) and not isinstance(exc, Exception):
self._write_to_self()
return handle
- def run_in_executor(self, executor, func, *args):
+ async def run_in_executor(self, executor, func, *args):
self._check_closed()
if self._debug:
self._check_callback(func, 'run_in_executor')
if executor is None:
executor = concurrent.futures.ThreadPoolExecutor()
self._default_executor = executor
- return futures.wrap_future(executor.submit(func, *args), loop=self)
+ return await futures.wrap_future(
+ executor.submit(func, *args), loop=self)
def set_default_executor(self, executor):
self._default_executor = executor
logger.debug(msg)
return addrinfo
- def getaddrinfo(self, host, port, *,
- family=0, type=0, proto=0, flags=0):
+ async def getaddrinfo(self, host, port, *,
+ family=0, type=0, proto=0, flags=0):
if self._debug:
- return self.run_in_executor(None, self._getaddrinfo_debug,
- host, port, family, type, proto, flags)
+ getaddr_func = self._getaddrinfo_debug
else:
- return self.run_in_executor(None, socket.getaddrinfo,
- host, port, family, type, proto, flags)
+ getaddr_func = socket.getaddrinfo
- def getnameinfo(self, sockaddr, flags=0):
- return self.run_in_executor(None, socket.getnameinfo, sockaddr, flags)
+ return await self.run_in_executor(
+ None, getaddr_func, host, port, family, type, proto, flags)
+
+ async def getnameinfo(self, sockaddr, flags=0):
+ return await self.run_in_executor(
+ None, socket.getnameinfo, sockaddr, flags)
async def create_connection(self, protocol_factory, host=None, port=None,
*, ssl=None, family=0,
raise ValueError(
'host/port and sock can not be specified at the same time')
- f1 = _ensure_resolved((host, port), family=family,
- type=socket.SOCK_STREAM, proto=proto,
- flags=flags, loop=self)
- fs = [f1]
- if local_addr is not None:
- f2 = _ensure_resolved(local_addr, family=family,
- type=socket.SOCK_STREAM, proto=proto,
- flags=flags, loop=self)
- fs.append(f2)
- else:
- f2 = None
-
- await tasks.wait(fs, loop=self)
-
- infos = f1.result()
+ infos = await self._ensure_resolved(
+ (host, port), family=family,
+ type=socket.SOCK_STREAM, proto=proto, flags=flags, loop=self)
if not infos:
raise OSError('getaddrinfo() returned empty list')
- if f2 is not None:
- laddr_infos = f2.result()
+
+ if local_addr is not None:
+ laddr_infos = await self._ensure_resolved(
+ local_addr, family=family,
+ type=socket.SOCK_STREAM, proto=proto,
+ flags=flags, loop=self)
if not laddr_infos:
raise OSError('getaddrinfo() returned empty list')
try:
sock = socket.socket(family=family, type=type, proto=proto)
sock.setblocking(False)
- if f2 is not None:
+ if local_addr is not None:
for _, _, _, _, laddr in laddr_infos:
try:
sock.bind(laddr)
assert isinstance(addr, tuple) and len(addr) == 2, (
'2-tuple is expected')
- infos = await _ensure_resolved(
+ infos = await self._ensure_resolved(
addr, family=family, type=socket.SOCK_DGRAM,
proto=proto, flags=flags, loop=self)
if not infos:
return transport, protocol
+ async def _ensure_resolved(self, address, *,
+ family=0, type=socket.SOCK_STREAM,
+ proto=0, flags=0, loop):
+ host, port = address[:2]
+ info = _ipaddr_info(host, port, family, type, proto)
+ if info is not None:
+ # "host" is already a resolved IP.
+ return [info]
+ else:
+ return await loop.getaddrinfo(host, port, family=family, type=type,
+ proto=proto, flags=flags)
+
async def _create_server_getaddrinfo(self, host, port, family, flags):
- infos = await _ensure_resolved((host, port), family=family,
- type=socket.SOCK_STREAM,
- flags=flags, loop=self)
+ infos = await self._ensure_resolved((host, port), family=family,
+ type=socket.SOCK_STREAM,
+ flags=flags, loop=self)
if not infos:
raise OSError(f'getaddrinfo({host!r}) returned empty list')
return infos
# Close the event loop
super().close()
- def sock_recv(self, sock, n):
- return self._proactor.recv(sock, n)
+ async def sock_recv(self, sock, n):
+ return await self._proactor.recv(sock, n)
- def sock_recv_into(self, sock, buf):
- return self._proactor.recv_into(sock, buf)
+ async def sock_recv_into(self, sock, buf):
+ return await self._proactor.recv_into(sock, buf)
- def sock_sendall(self, sock, data):
- return self._proactor.send(sock, data)
+ async def sock_sendall(self, sock, data):
+ return await self._proactor.send(sock, data)
- def sock_connect(self, sock, address):
- return self._proactor.connect(sock, address)
+ async def sock_connect(self, sock, address):
+ return await self._proactor.connect(sock, address)
- def sock_accept(self, sock):
- return self._proactor.accept(sock)
+ async def sock_accept(self, sock):
+ return await self._proactor.accept(sock)
def _close_self_pipe(self):
if self._self_reading_future is not None:
self._ensure_fd_no_transport(fd)
return self._remove_writer(fd)
- def sock_recv(self, sock, n):
+ async def sock_recv(self, sock, n):
"""Receive data from the socket.
The return value is a bytes object representing the data received.
The maximum amount of data to be received at once is specified by
nbytes.
-
- This method is a coroutine.
"""
if self._debug and sock.gettimeout() != 0:
raise ValueError("the socket must be non-blocking")
fut = self.create_future()
self._sock_recv(fut, None, sock, n)
- return fut
+ return await fut
def _sock_recv(self, fut, registered_fd, sock, n):
# _sock_recv() can add itself as an I/O callback if the operation can't
else:
fut.set_result(data)
- def sock_recv_into(self, sock, buf):
+ async def sock_recv_into(self, sock, buf):
"""Receive data from the socket.
The received data is written into *buf* (a writable buffer).
The return value is the number of bytes written.
-
- This method is a coroutine.
"""
if self._debug and sock.gettimeout() != 0:
raise ValueError("the socket must be non-blocking")
fut = self.create_future()
self._sock_recv_into(fut, None, sock, buf)
- return fut
+ return await fut
def _sock_recv_into(self, fut, registered_fd, sock, buf):
# _sock_recv_into() can add itself as an I/O callback if the operation
else:
fut.set_result(nbytes)
- def sock_sendall(self, sock, data):
+ async def sock_sendall(self, sock, data):
"""Send data to the socket.
The socket must be connected to a remote socket. This method continues
error occurs. None is returned on success. On error, an exception is
raised, and there is no way to determine how much data, if any, was
successfully processed by the receiving end of the connection.
-
- This method is a coroutine.
"""
if self._debug and sock.gettimeout() != 0:
raise ValueError("the socket must be non-blocking")
self._sock_sendall(fut, None, sock, data)
else:
fut.set_result(None)
- return fut
+ return await fut
def _sock_sendall(self, fut, registered_fd, sock, data):
if registered_fd is not None:
raise ValueError("the socket must be non-blocking")
if not hasattr(socket, 'AF_UNIX') or sock.family != socket.AF_UNIX:
- resolved = base_events._ensure_resolved(
+ resolved = await self._ensure_resolved(
address, family=sock.family, proto=sock.proto, loop=self)
- if not resolved.done():
- await resolved
- _, _, _, _, address = resolved.result()[0]
+ _, _, _, _, address = resolved[0]
fut = self.create_future()
self._sock_connect(fut, sock, address)
else:
fut.set_result(None)
- def sock_accept(self, sock):
+ async def sock_accept(self, sock):
"""Accept a connection.
The socket must be bound to an address and listening for connections.
The return value is a pair (conn, address) where conn is a new socket
object usable to send and receive data on the connection, and address
is the address bound to the socket on the other end of the connection.
-
- This method is a coroutine.
"""
if self._debug and sock.gettimeout() != 0:
raise ValueError("the socket must be non-blocking")
fut = self.create_future()
self._sock_accept(fut, False, sock)
- return fut
+ return await fut
def _sock_accept(self, fut, registered, sock):
fd = sock.fileno()
self.loop.set_default_executor(executor)
self.assertIs(executor, self.loop._default_executor)
- def test_getnameinfo(self):
- sockaddr = mock.Mock()
- self.loop.run_in_executor = mock.Mock()
- self.loop.getnameinfo(sockaddr)
- self.assertEqual(
- (None, socket.getnameinfo, sockaddr, 0),
- self.loop.run_in_executor.call_args[0])
-
def test_call_soon(self):
def cb():
pass
# check disabled if debug mode is disabled
test_thread(self.loop, False, create_loop=True)
- def test_run_once_in_executor_plain(self):
- def cb():
- pass
- f = asyncio.Future(loop=self.loop)
- executor = mock.Mock()
- executor.submit.return_value = f
-
- self.loop.set_default_executor(executor)
-
- res = self.loop.run_in_executor(None, cb)
- self.assertIs(f, res)
-
- executor = mock.Mock()
- executor.submit.return_value = f
- res = self.loop.run_in_executor(executor, cb)
- self.assertIs(f, res)
- self.assertTrue(executor.submit.called)
-
- f.cancel() # Don't complain about abandoned Future.
-
def test__run_once(self):
h1 = asyncio.TimerHandle(time.monotonic() + 5.0, lambda: True, (),
self.loop)
self.loop = asyncio.new_event_loop()
self.set_event_loop(self.loop)
+ @mock.patch('socket.getnameinfo')
+ def test_getnameinfo(self, m_gai):
+ m_gai.side_effect = lambda *args: 42
+ r = self.loop.run_until_complete(self.loop.getnameinfo(('abc', 123)))
+ self.assertEqual(r, 42)
+
@patch_socket
def test_create_connection_multiple_errors(self, m_socket):
OSError, self.loop.run_until_complete, coro)
def test_create_connection_connect_err(self):
- @asyncio.coroutine
- def getaddrinfo(*args, **kw):
- yield from []
+ async def getaddrinfo(*args, **kw):
return [(2, 1, 6, '', ('107.6.106.82', 80))]
def getaddrinfo_task(*args, **kwds):
self.assertTrue(m_log.error.called)
self.assertFalse(sock.close.called)
self.loop._remove_reader.assert_called_with(10)
- self.loop.call_later.assert_called_with(constants.ACCEPT_RETRY_DELAY,
- # self.loop._start_serving
- mock.ANY,
- MyProto, sock, None, None, mock.ANY)
+ self.loop.call_later.assert_called_with(
+ constants.ACCEPT_RETRY_DELAY,
+ # self.loop._start_serving
+ mock.ANY,
+ MyProto, sock, None, None, mock.ANY)
def test_call_coroutine(self):
@asyncio.coroutine
with self.assertRaises(TypeError):
self.loop.call_at(self.loop.time() + 60, func)
with self.assertRaises(TypeError):
- self.loop.run_in_executor(None, func)
+ self.loop.run_until_complete(
+ self.loop.run_in_executor(None, func))
@mock.patch('asyncio.base_events.logger')
def test_log_slow_callbacks(self, m_logger):
def test_prompt_cancellation(self):
r, w = socket.socketpair()
r.setblocking(False)
- f = self.loop.sock_recv(r, 1)
+ f = self.loop.create_task(self.loop.sock_recv(r, 1))
ov = getattr(f, 'ov', None)
if ov is not None:
self.assertTrue(ov.pending)
with self.assertRaises(RuntimeError):
self.loop.call_at(self.loop.time() + .0, func)
with self.assertRaises(RuntimeError):
- self.loop.run_in_executor(None, func)
+ self.loop.run_until_complete(
+ self.loop.run_in_executor(None, func))
with self.assertRaises(RuntimeError):
self.loop.create_task(coro)
with self.assertRaises(RuntimeError):
self.loop.close()
self.assertFalse(self.loop._close_self_pipe.called)
- def test_sock_recv(self):
- self.loop.sock_recv(self.sock, 1024)
- self.proactor.recv.assert_called_with(self.sock, 1024)
-
- def test_sock_recv_into(self):
- buf = bytearray(10)
- self.loop.sock_recv_into(self.sock, buf)
- self.proactor.recv_into.assert_called_with(self.sock, buf)
-
- def test_sock_sendall(self):
- self.loop.sock_sendall(self.sock, b'data')
- self.proactor.send.assert_called_with(self.sock, b'data')
-
- def test_sock_connect(self):
- self.loop.sock_connect(self.sock, ('1.2.3.4', 123))
- self.proactor.connect.assert_called_with(self.sock, ('1.2.3.4', 123))
-
- def test_sock_accept(self):
- self.loop.sock_accept(self.sock)
- self.proactor.accept.assert_called_with(self.sock)
-
def test_make_socket_transport(self):
tr = self.loop._make_socket_transport(self.sock, asyncio.Protocol())
self.assertIsInstance(tr, _ProactorSocketTransport)
sock = test_utils.mock_nonblocking_socket()
self.loop._sock_recv = mock.Mock()
- f = self.loop.sock_recv(sock, 1024)
- self.assertIsInstance(f, asyncio.Future)
- self.loop._sock_recv.assert_called_with(f, None, sock, 1024)
+ f = self.loop.create_task(self.loop.sock_recv(sock, 1024))
+ self.loop.run_until_complete(asyncio.sleep(0.01, loop=self.loop))
+
+ self.assertEqual(self.loop._sock_recv.call_args[0][1:],
+ (None, sock, 1024))
+
+ f.cancel()
+ with self.assertRaises(asyncio.CancelledError):
+ self.loop.run_until_complete(f)
def test_sock_recv_reconnection(self):
sock = mock.Mock()
self.loop.add_reader = mock.Mock()
self.loop.remove_reader = mock.Mock()
- fut = self.loop.sock_recv(sock, 1024)
+ fut = self.loop.create_task(
+ self.loop.sock_recv(sock, 1024))
+
+ self.loop.run_until_complete(asyncio.sleep(0.01, loop=self.loop))
+
callback = self.loop.add_reader.call_args[0][1]
params = self.loop.add_reader.call_args[0][2:]
sock.recv.side_effect = OSError(9)
callback(*params)
+ self.loop.run_until_complete(asyncio.sleep(0.01, loop=self.loop))
+
self.assertIsInstance(fut.exception(), OSError)
self.assertEqual((10,), self.loop.remove_reader.call_args[0])
sock = test_utils.mock_nonblocking_socket()
self.loop._sock_sendall = mock.Mock()
- f = self.loop.sock_sendall(sock, b'data')
- self.assertIsInstance(f, asyncio.Future)
+ f = self.loop.create_task(
+ self.loop.sock_sendall(sock, b'data'))
+
+ self.loop.run_until_complete(asyncio.sleep(0.01, loop=self.loop))
+
self.assertEqual(
- (f, None, sock, b'data'),
- self.loop._sock_sendall.call_args[0])
+ (None, sock, b'data'),
+ self.loop._sock_sendall.call_args[0][1:])
+
+ f.cancel()
+ with self.assertRaises(asyncio.CancelledError):
+ self.loop.run_until_complete(f)
def test_sock_sendall_nodata(self):
sock = test_utils.mock_nonblocking_socket()
self.loop._sock_sendall = mock.Mock()
- f = self.loop.sock_sendall(sock, b'')
- self.assertIsInstance(f, asyncio.Future)
+ f = self.loop.create_task(self.loop.sock_sendall(sock, b''))
+ self.loop.run_until_complete(asyncio.sleep(0, loop=self.loop))
+
self.assertTrue(f.done())
self.assertIsNone(f.result())
self.assertFalse(self.loop._sock_sendall.called)
self.loop.add_writer = mock.Mock()
self.loop.remove_writer = mock.Mock()
- fut = self.loop.sock_sendall(sock, b'data')
+ fut = self.loop.create_task(self.loop.sock_sendall(sock, b'data'))
+
+ self.loop.run_until_complete(asyncio.sleep(0.01, loop=self.loop))
+
callback = self.loop.add_writer.call_args[0][1]
params = self.loop.add_writer.call_args[0][2:]
sock.send.side_effect = OSError(9)
callback(*params)
+ self.loop.run_until_complete(asyncio.sleep(0.01, loop=self.loop))
+
self.assertIsInstance(fut.exception(), OSError)
self.assertEqual((10,), self.loop.remove_writer.call_args[0])
def test_sock_connect_resolve_using_socket_params(self, m_gai):
addr = ('need-resolution.com', 8080)
sock = test_utils.mock_nonblocking_socket()
- m_gai.side_effect = (None, None, None, None, ('127.0.0.1', 0))
- m_gai._is_coroutine = False
+
+ m_gai.side_effect = \
+ lambda *args: [(None, None, None, None, ('127.0.0.1', 0))]
+
con = self.loop.create_task(self.loop.sock_connect(sock, addr))
- while not m_gai.called:
- self.loop._run_once()
+ self.loop.run_until_complete(con)
m_gai.assert_called_with(
addr[0], addr[1], sock.family, sock.type, sock.proto, 0)
- con.cancel()
- with self.assertRaises(asyncio.CancelledError):
- self.loop.run_until_complete(con)
+ self.loop.run_until_complete(con)
+ sock.connect.assert_called_with(('127.0.0.1', 0))
def test__sock_connect(self):
f = asyncio.Future(loop=self.loop)
sock = test_utils.mock_nonblocking_socket()
self.loop._sock_accept = mock.Mock()
- f = self.loop.sock_accept(sock)
- self.assertIsInstance(f, asyncio.Future)
- self.assertEqual(
- (f, False, sock), self.loop._sock_accept.call_args[0])
+ f = self.loop.create_task(self.loop.sock_accept(sock))
+ self.loop.run_until_complete(asyncio.sleep(0.01, loop=self.loop))
+
+ self.assertFalse(self.loop._sock_accept.call_args[0][1])
+ self.assertIs(self.loop._sock_accept.call_args[0][2], sock)
+
+ f.cancel()
+ with self.assertRaises(asyncio.CancelledError):
+ self.loop.run_until_complete(f)
def test__sock_accept(self):
f = asyncio.Future(loop=self.loop)
def test_run_coroutine_threadsafe_task_factory_exception(self):
"""Test coroutine submission from a tread to an event loop
when the task factory raise an exception."""
- # Schedule the target
- future = self.loop.run_in_executor(
- None, lambda: self.target(advance_coro=True))
- # Set corrupted task factory
- self.loop.set_task_factory(lambda loop, coro: wrong_name)
+
+ def task_factory(loop, coro):
+ raise NameError
+
+ run = self.loop.create_task(
+ self.loop.run_in_executor(
+ None, lambda: self.target(advance_coro=True)))
+
# Set exception handler
callback = test_utils.MockCallback()
self.loop.set_exception_handler(callback)
+
+ # Set corrupted task factory
+ self.loop.set_task_factory(task_factory)
+
# Run event loop
with self.assertRaises(NameError) as exc_context:
- self.loop.run_until_complete(future)
+ self.loop.run_until_complete(run)
+
# Check exceptions
- self.assertIn('wrong_name', exc_context.exception.args[0])
self.assertEqual(len(callback.call_args_list), 1)
(loop, context), kwargs = callback.call_args
self.assertEqual(context['exception'], exc_context.exception)
def test_close(self):
a, b = socket.socketpair()
trans = self.loop._make_socket_transport(a, asyncio.Protocol())
- f = asyncio.ensure_future(self.loop.sock_recv(b, 100))
+ f = asyncio.ensure_future(self.loop.sock_recv(b, 100), loop=self.loop)
trans.close()
self.loop.run_until_complete(f)
self.assertEqual(f.result(), b'')
--- /dev/null
+Convert asyncio functions that were documented as coroutines to coroutines.
+Affected functions: loop.sock_sendall, loop.sock_recv, loop.sock_accept,
+loop.run_in_executor, loop.getaddrinfo, loop.getnameinfo.