classification
Title: Document how to close the TCPServer listening socket
Type: enhancement Stage: resolved
Components: Documentation Versions: Python 3.4, Python 3.5, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: berker.peksag, demian.brecht, docs@python, martin.panter, python-dev, r.david.murray, rbcollins, vstinner
Priority: normal Keywords: patch

Created on 2015-01-17 04:32 by martin.panter, last changed 2015-07-29 00:57 by rbcollins. This issue is now closed.

Files
File name Uploaded Description Edit
server_close.patch martin.panter, 2015-01-31 12:26 review
server_close.v2.patch martin.panter, 2015-02-27 23:57 review
Messages (8)
msg234161 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2015-01-17 04:32
Running the example from the Asynchronous Mixins section of the “socketserver” documentation generates a ResourceWarning:

$ ./python -btWall ThreadedTCPServer.py
Server loop running in thread: Thread-1
Received: Thread-2: Hello World 1
Received: Thread-3: Hello World 2
Received: Thread-4: Hello World 3
sys:1: ResourceWarning: unclosed <socket.socket fd=3, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0, laddr=('127.0.0.1', 43804)>

There is a server_close() method mentioned in the doc string of the BaseServer class, so I assume it is meant to be part of the API. But there is no mention of it in the reference documentation.

I think server.server_close() should be documented, and called after server.shutdown() in the example. A further enhancement might be to turn BaseServer into a context manager, but I would be happy with using the existing server_close() method.
msg235105 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2015-01-31 12:26
Here is a simple patch to add server_close() to the documentation, and a simple test to ensure it closes the socket.
msg236639 - (view) Author: Demian Brecht (demian.brecht) * (Python triager) Date: 2015-02-26 01:14
Left a couple small nitpicks in Rietveld. Otherwise LGTM.
msg236859 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2015-02-27 23:57
Posting server_close.v2.patch, which tests fileno(), and uses a single space between the new sentences. Also added a bit to the how-to at the top (using doubly-spaced sentences to match the rest of the paragraph).
msg236860 - (view) Author: Demian Brecht (demian.brecht) * (Python triager) Date: 2015-02-28 00:53
LGTM. I'm not sure whether or not it's eligible for 3.4 though as it's a documentation and not a functional fix.
msg236866 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2015-02-28 05:48
In general documentation changes go in all maintained versions (ie: right now that would be 2.7, 3.4, and default/3.5).  The only exception, really, would be if the change didn't apply to one or more of the versions because of code differences.  (Note: I haven't reviewed the patch itself yet ;)
msg247550 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-07-29 00:55
New changeset 8afd995802a6 by Robert Collins in branch '2.7':
Issue #23254: Document how to close the TCPServer listening socket.
https://hg.python.org/cpython/rev/8afd995802a6

New changeset 1123de53195e by Robert Collins in branch '3.4':
Issue #23254: Document how to close the TCPServer listening socket.
https://hg.python.org/cpython/rev/1123de53195e

New changeset 5ee8a4efc06f by Robert Collins in branch '3.5':
Issue #23254: Document how to close the TCPServer listening socket.
https://hg.python.org/cpython/rev/5ee8a4efc06f

New changeset 256d5c7146cb by Robert Collins in branch 'default':
Issue #23254: Document how to close the TCPServer listening socket.
https://hg.python.org/cpython/rev/256d5c7146cb
msg247551 - (view) Author: Robert Collins (rbcollins) * (Python committer) Date: 2015-07-29 00:57
Applied to 2.7/3.4/3.5/3.6. Thanks!
History
Date User Action Args
2015-07-29 00:57:29rbcollinssetstatus: open -> closed

nosy: + rbcollins
messages: + msg247551

resolution: fixed
stage: commit review -> resolved
2015-07-29 00:55:57python-devsetnosy: + python-dev
messages: + msg247550
2015-02-28 05:48:30r.david.murraysetnosy: + r.david.murray

messages: + msg236866
versions: + Python 2.7
2015-02-28 00:53:28demian.brechtsetmessages: + msg236860
stage: patch review -> commit review
2015-02-27 23:57:26martin.pantersetfiles: + server_close.v2.patch

messages: + msg236859
2015-02-26 01:14:58demian.brechtsetnosy: + demian.brecht
messages: + msg236639
2015-02-02 16:27:58vstinnersetnosy: + vstinner
2015-02-02 02:55:48berker.peksagsetnosy: + berker.peksag

stage: patch review
2015-01-31 12:26:07martin.pantersetfiles: + server_close.patch
keywords: + patch
messages: + msg235105

versions: + Python 3.4, Python 3.5
2015-01-17 04:32:54martin.pantercreate