[Python-checkins] cpython (merge 3.5 -> default): Issue #23254: Document how to close the TCPServer listening socket.
robert.collins
python-checkins at python.org
Wed Jul 29 02:55:50 CEST 2015
https://hg.python.org/cpython/rev/256d5c7146cb
changeset: 97115:256d5c7146cb
parent: 97111:3cf560285315
parent: 97114:5ee8a4efc06f
user: Robert Collins <rbtcollins at hp.com>
date: Wed Jul 29 12:55:33 2015 +1200
summary:
Issue #23254: Document how to close the TCPServer listening socket.
Patch from Martin Panter.
files:
Doc/library/socketserver.rst | 13 +++++++++++--
Lib/test/test_socketserver.py | 1 +
Misc/NEWS | 3 +++
3 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/Doc/library/socketserver.rst b/Doc/library/socketserver.rst
--- a/Doc/library/socketserver.rst
+++ b/Doc/library/socketserver.rst
@@ -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 --git a/Lib/test/test_socketserver.py b/Lib/test/test_socketserver.py
--- a/Lib/test/test_socketserver.py
+++ b/Lib/test/test_socketserver.py
@@ -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 --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -13,6 +13,9 @@
Library
-------
+- Issue #23254: Document how to close the TCPServer listening socket.
+ Patch from Martin Panter.
+
- Issue #23426: run_setup was broken in distutils.
Patch from Alexander Belopolsky.
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list