This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author yselivanov
Recipients asvetlov, yselivanov
Date 2018-01-25.06:44:24
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
As discussed, we want to make Server objects more usable in async/await code and more compatible with

This is also needed to handle a use case when two or more servers are created and need to start listening at the same time.

We propose to:

1. Add a new bool flag defaulting to True to loop.create_server and loop.create_unix_server: start_serving.  By default, loop will return a server that is already accepting connections.  When start_serving is set to False, create_server and create_unix_server will return a server that will not listen on its sockets.

2. A new idempotent Server.start_serving() method can be used to make server listen on its sockets (useful when a server object was created with start_serving=False).

3. A new Server.serve_forever() method that calls start_serving() and blocks forever, until cancelled.  When cancelled, it closes its server object.

4. A new Server.is_serving() method.  This is useful to introspect a server object in unittests.

5. Server objects should be async context managers.  Server.__aexit__ should close the server and await on Server.wait_closed().

With these new APIs, the following pattern becomes possible:

    async def main():
        srv = await asyncio.start_server(...)
        async with srv:
            await srv.serve_forever()
Date User Action Args
2018-01-25 06:44:24yselivanovsetrecipients: + yselivanov, asvetlov
2018-01-25 06:44:24yselivanovsetmessageid: <>
2018-01-25 06:44:24yselivanovlinkissue32662 messages
2018-01-25 06:44:24yselivanovcreate