changeset: 97113:1123de53195e branch: 3.4 parent: 97101:1003746ee7a0 user: Robert Collins date: Wed Jul 29 12:52:40 2015 +1200 files: Doc/library/socketserver.rst Lib/test/test_socketserver.py Misc/NEWS description: Issue #23254: Document how to close the TCPServer listening socket. Patch from Martin Panter. diff -r 1003746ee7a0 -r 1123de53195e Doc/library/socketserver.rst --- a/Doc/library/socketserver.rst Tue Jul 28 11:05:18 2015 -0700 +++ b/Doc/library/socketserver.rst Wed Jul 29 12:52:40 2015 +1200 @@ -33,9 +33,10 @@ handler class by subclassing the :class:`BaseRequestHandler` class and overriding its :meth:`handle` method; this method will process incoming requests. Second, you must instantiate one of the server classes, passing it -the server's address and the request handler class. Finally, call the +the server's address and the request handler class. Then call the :meth:`handle_request` or :meth:`serve_forever` method of the server object to -process one or many requests. +process one or many requests. Finally, call :meth:`~BaseServer.server_close` +to close the socket. When inheriting from :class:`ThreadingMixIn` for threaded connection behavior, you should explicitly declare how you want your threads to behave on an abrupt @@ -177,6 +178,13 @@ Tell the :meth:`serve_forever` loop to stop and wait until it does. +.. method:: BaseServer.server_close() + + Clean up the server. May be overridden. + + .. versionadded:: 2.6 + + .. attribute:: BaseServer.address_family The family of protocols to which the server's socket belongs. @@ -547,6 +555,7 @@ client(ip, port, "Hello World 3") server.shutdown() + server.server_close() The output of the example should look something like this:: diff -r 1003746ee7a0 -r 1123de53195e Lib/test/test_socketserver.py --- a/Lib/test/test_socketserver.py Tue Jul 28 11:05:18 2015 -0700 +++ b/Lib/test/test_socketserver.py Wed Jul 29 12:52:40 2015 +1200 @@ -144,6 +144,7 @@ server.shutdown() t.join() server.server_close() + self.assertEqual(-1, server.socket.fileno()) if verbose: print("done") def stream_examine(self, proto, addr): diff -r 1003746ee7a0 -r 1123de53195e Misc/NEWS --- a/Misc/NEWS Tue Jul 28 11:05:18 2015 -0700 +++ b/Misc/NEWS Wed Jul 29 12:52:40 2015 +1200 @@ -66,6 +66,9 @@ Library ------- +- Issue #23254: Document how to close the TCPServer listening socket. + Patch from Martin Panter. + - Issue #19450: Update Windows builds to use SQLite 3.8.11.0 - Issue #23441: rcompleter now prints a tab character instead of displaying