summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobert Collins <rbtcollins@hp.com>2015-07-29 00:48:42 (GMT)
committerRobert Collins <rbtcollins@hp.com>2015-07-29 00:48:42 (GMT)
commit2f2c829688a42828d2be85118d26ea5bb41266eb (patch)
tree4d4183de9fa4787d1670f2fa229d2929ead91926
parent62a23383dd5ce467a722ccdb4a306287c62005f9 (diff)
downloadcpython-2f2c829688a42828d2be85118d26ea5bb41266eb.zip
cpython-2f2c829688a42828d2be85118d26ea5bb41266eb.tar.gz
cpython-2f2c829688a42828d2be85118d26ea5bb41266eb.tar.bz2
Issue #23254: Document how to close the TCPServer listening socket.
Patch from Martin Panter.
-rw-r--r--Doc/library/socketserver.rst13
-rw-r--r--Lib/test/test_socketserver.py2
-rw-r--r--Misc/NEWS3
3 files changed, 16 insertions, 2 deletions
diff --git a/Doc/library/socketserver.rst b/Doc/library/socketserver.rst
index a9053d1..bb933a6 100644
--- a/Doc/library/socketserver.rst
+++ b/Doc/library/socketserver.rst
@@ -39,9 +39,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
@@ -170,6 +171,13 @@ Server Objects
.. versionadded:: 2.6
+.. 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.
@@ -540,6 +548,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 8707017..714ca4a 100644
--- a/Lib/test/test_socketserver.py
+++ b/Lib/test/test_socketserver.py
@@ -158,6 +158,8 @@ class SocketServerTest(unittest.TestCase):
if verbose: print "waiting for server"
server.shutdown()
t.join()
+ server.server_close()
+ self.assertRaises(socket.error, server.socket.fileno)
if verbose: print "done"
def stream_examine(self, proto, addr):
diff --git a/Misc/NEWS b/Misc/NEWS
index c2ca4e8..e861175 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -34,6 +34,9 @@ Core and Builtins
Library
-------
+- Issue #23254: Document how to close the TCPServer listening socket.
+ Patch from Martin Panter.
+
- Issue #17527: Add PATCH to wsgiref.validator. Patch from Luca Sbardella.
- Issue #24613: Calling array.fromstring() with self is no longer allowed