bpo-32662: Implement Server.start_serving() and Server.serve_forever() by 1st1 · Pull Request #5312 · python/cpython (original) (raw)
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, we document this method as idempotent as related to server already accepting connections. I.e. it's fine to do this:
await server.start_serving() await server.serve_forever()
The reason for this design is backwards-compatibility: loop.create_server
by default returns a Server object that's already serving! So server.serve_forever()
must be idempotent.
I found the utility in server.start_serving()
when I was writing unittests. Sometimes we need to deterministically know when a server just started to listen, otherwise, for instance, it would be impossible for me to write a working loop.create_unix_server
unittest.