diff options
author | Robert Collins <rbtcollins@hp.com> | 2015-07-29 00:53:30 (GMT) |
---|---|---|
committer | Robert Collins <rbtcollins@hp.com> | 2015-07-29 00:53:30 (GMT) |
commit | f7e3b5e153718931631e7fdf21779843e6e73379 (patch) | |
tree | 5bd0361e65ff14676ca4562396f38be8cc14dc98 | |
parent | ace8848df69ba927c6fb4af7fffef706a1a19279 (diff) | |
parent | 1ee9283254446998c9f423896b1edffe42f246d3 (diff) | |
download | cpython-f7e3b5e153718931631e7fdf21779843e6e73379.zip cpython-f7e3b5e153718931631e7fdf21779843e6e73379.tar.gz cpython-f7e3b5e153718931631e7fdf21779843e6e73379.tar.bz2 |
Issue #23254: Document how to close the TCPServer listening socket.
Patch from Martin Panter.
-rw-r--r-- | Doc/library/socketserver.rst | 13 | ||||
-rw-r--r-- | Lib/test/test_socketserver.py | 1 | ||||
-rw-r--r-- | Misc/NEWS | 3 |
3 files changed, 15 insertions, 2 deletions
diff --git a/Doc/library/socketserver.rst b/Doc/library/socketserver.rst index 9db36d5..18be936 100644 --- a/Doc/library/socketserver.rst +++ b/Doc/library/socketserver.rst @@ -33,9 +33,10 @@ Creating a server requires several steps. First, you must create a request 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 @@ Server Objects 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 @@ An example for the :class:`ThreadingMixIn` class:: client(ip, port, "Hello World 3") server.shutdown() + server.server_close() The output of the example should look something like this:: diff --git a/Lib/test/test_socketserver.py b/Lib/test/test_socketserver.py index 31ab3b6..1ea66a6 100644 --- a/Lib/test/test_socketserver.py +++ b/Lib/test/test_socketserver.py @@ -144,6 +144,7 @@ class SocketServerTest(unittest.TestCase): server.shutdown() t.join() server.server_close() + self.assertEqual(-1, server.socket.fileno()) if verbose: print("done") def stream_examine(self, proto, addr): @@ -13,6 +13,9 @@ Core and Builtins 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 #17527: Add PATCH to wsgiref.validator. Patch from Luca Sbardella. |