mirror of
https://github.com/python/cpython.git
synced 2025-11-03 03:22:27 +00:00
asyncio: improve the documentation of servers
- Fix the documentation of Server.close(): it closes sockets - Replace AbstractServer with Server - Document Server.sockets attribute
This commit is contained in:
parent
b28dbac86d
commit
8ebeb03740
3 changed files with 33 additions and 19 deletions
|
|
@ -263,8 +263,9 @@ Creating listening connections
|
||||||
|
|
||||||
.. method:: BaseEventLoop.create_server(protocol_factory, host=None, port=None, \*, family=socket.AF_UNSPEC, flags=socket.AI_PASSIVE, sock=None, backlog=100, ssl=None, reuse_address=None)
|
.. method:: BaseEventLoop.create_server(protocol_factory, host=None, port=None, \*, family=socket.AF_UNSPEC, flags=socket.AI_PASSIVE, sock=None, backlog=100, ssl=None, reuse_address=None)
|
||||||
|
|
||||||
Create a TCP server bound to host and port. Return an
|
Create a TCP server bound to host and port. Return a :class:`Server` object,
|
||||||
:class:`AbstractServer` object which can be used to stop the service.
|
its :attr:`~Server.sockets` attribute contains created sockets. Use the
|
||||||
|
:meth:`Server.close` method to stop the server: close listening sockets.
|
||||||
|
|
||||||
This method is a :ref:`coroutine <coroutine>`.
|
This method is a :ref:`coroutine <coroutine>`.
|
||||||
|
|
||||||
|
|
@ -557,17 +558,31 @@ Debug mode
|
||||||
Server
|
Server
|
||||||
------
|
------
|
||||||
|
|
||||||
.. class:: AbstractServer
|
.. class:: Server
|
||||||
|
|
||||||
Abstract server returned by :func:`BaseEventLoop.create_server`.
|
Server listening on sockets.
|
||||||
|
|
||||||
|
Object created by the :meth:`BaseEventLoop.create_server` method and the
|
||||||
|
:func:`start_server` function. Don't instanciate the class directly.
|
||||||
|
|
||||||
.. method:: close()
|
.. method:: close()
|
||||||
|
|
||||||
Stop serving. This leaves existing connections open.
|
Stop serving: close all sockets and set the :attr:`sockets` attribute to
|
||||||
|
``None``.
|
||||||
|
|
||||||
|
The server is closed asynchonously, use the :meth:`wait_closed` coroutine
|
||||||
|
to wait until the server is closed.
|
||||||
|
|
||||||
.. method:: wait_closed()
|
.. method:: wait_closed()
|
||||||
|
|
||||||
A :ref:`coroutine <coroutine>` to wait until service is closed.
|
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
|
||||||
|
``None`` if the server is closed.
|
||||||
|
|
||||||
|
|
||||||
Handle
|
Handle
|
||||||
|
|
|
||||||
|
|
@ -34,29 +34,26 @@ Stream functions
|
||||||
|
|
||||||
.. function:: start_server(client_connected_cb, host=None, port=None, \*, loop=None, limit=None, **kwds)
|
.. function:: start_server(client_connected_cb, host=None, port=None, \*, loop=None, limit=None, **kwds)
|
||||||
|
|
||||||
Start a socket server, with a callback for each client connected.
|
Start a socket server, with a callback for each client connected. The return
|
||||||
|
value is the same as :meth:`~BaseEventLoop.create_server()`.
|
||||||
|
|
||||||
The first parameter, *client_connected_cb*, takes two parameters:
|
The *client_connected_cb* parameter is called with two parameters:
|
||||||
*client_reader*, *client_writer*. *client_reader* is a
|
*client_reader*, *client_writer*. *client_reader* is a
|
||||||
:class:`StreamReader` object, while *client_writer* is a
|
:class:`StreamReader` object, while *client_writer* is a
|
||||||
:class:`StreamWriter` object. This parameter can either be a plain callback
|
:class:`StreamWriter` object. The *client_connected_cb* parameter can
|
||||||
function or a :ref:`coroutine function <coroutine>`; if it is a coroutine
|
either be a plain callback function or a :ref:`coroutine function
|
||||||
function, it will be automatically wrapped in a future using the
|
<coroutine>`; if it is a coroutine function, it will be automatically
|
||||||
:meth:`BaseEventLoop.create_task` method.
|
wrapped in a future using the :meth:`BaseEventLoop.create_task` method.
|
||||||
|
|
||||||
The rest of the arguments are all the usual arguments to
|
The rest of the arguments are all the usual arguments to
|
||||||
:meth:`~BaseEventLoop.create_server()` except *protocol_factory*; most
|
:meth:`~BaseEventLoop.create_server()` except *protocol_factory*; most
|
||||||
common are positional host and port, with various optional keyword arguments
|
common are positional *host* and *port*, with various optional keyword
|
||||||
following. The return value is the same as
|
arguments following.
|
||||||
:meth:`~BaseEventLoop.create_server()`.
|
|
||||||
|
|
||||||
Additional optional keyword arguments are *loop* (to set the event loop
|
Additional optional keyword arguments are *loop* (to set the event loop
|
||||||
instance to use) and *limit* (to set the buffer limit passed to the
|
instance to use) and *limit* (to set the buffer limit passed to the
|
||||||
:class:`StreamReader`).
|
:class:`StreamReader`).
|
||||||
|
|
||||||
The return value is the same as :meth:`~BaseEventLoop.create_server()`, i.e.
|
|
||||||
a :class:`AbstractServer` object which can be used to stop the service.
|
|
||||||
|
|
||||||
This function is a :ref:`coroutine <coroutine>`.
|
This function is a :ref:`coroutine <coroutine>`.
|
||||||
|
|
||||||
.. function:: open_unix_connection(path=None, \*, loop=None, limit=None, **kwds)
|
.. function:: open_unix_connection(path=None, \*, loop=None, limit=None, **kwds)
|
||||||
|
|
|
||||||
|
|
@ -110,6 +110,8 @@ class Server(events.AbstractServer):
|
||||||
return
|
return
|
||||||
self.sockets = None
|
self.sockets = None
|
||||||
for sock in sockets:
|
for sock in sockets:
|
||||||
|
# closing sockets will call asynchronously the _detach() method
|
||||||
|
# which calls _wakeup() for the last socket
|
||||||
self._loop._stop_serving(sock)
|
self._loop._stop_serving(sock)
|
||||||
if self._active_count == 0:
|
if self._active_count == 0:
|
||||||
self._wakeup()
|
self._wakeup()
|
||||||
|
|
@ -626,7 +628,7 @@ class BaseEventLoop(events.AbstractEventLoop):
|
||||||
reuse_address=None):
|
reuse_address=None):
|
||||||
"""Create a TCP server bound to host and port.
|
"""Create a TCP server bound to host and port.
|
||||||
|
|
||||||
Return an AbstractServer object which can be used to stop the service.
|
Return an Server object which can be used to stop the service.
|
||||||
|
|
||||||
This method is a coroutine.
|
This method is a coroutine.
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue