Author martin.panter
Recipients martin.panter, palaviv, terry.reedy
Date 2016-02-29.22:54:50
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1456786491.18.0.00686604672056.issue26404@psf.upfronthosting.co.za>
In-reply-to
Content
Server_close() was only documentated last year; see Issue 23254. For the examples that run until you interrupt them, the servers currently emit a resource warning (in addition to the KeyboardInterrupt traceback and the Python 2 bytes warnings):

$ python -bWall TCPServer.py
127.0.0.1 wrote:
TCPServer.py:16: BytesWarning: str() on a bytes instance
  print(self.data)
b'hello world with TCP'
127.0.0.1 wrote:
TCPServer.py:16: BytesWarning: str() on a bytes instance
  print(self.data)
b'python is nice'
^CTraceback (most recent call last):
  File "TCPServer.py", line 28, in <module>
    server.serve_forever()
  File "/usr/lib/python3.5/socketserver.py", line 237, in serve_forever
    ready = selector.select(poll_interval)
  File "/usr/lib/python3.5/selectors.py", line 367, in select
    fd_event_list = self._poll.poll(timeout)
KeyboardInterrupt
sys:1: ResourceWarning: unclosed <socket.socket fd=3, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0, laddr=('127.0.0.1', 9999)>
[Exit 1]

If you ignore the warning, there isn’t much effective difference, because the socket gets closed when the process exits, or if you are lucky, when Python garbage collects the global “server” object. But IMO it is bad practice not to clean up resources properly, especially in an API example.
History
Date User Action Args
2016-02-29 22:54:51martin.pantersetrecipients: + martin.panter, terry.reedy, palaviv
2016-02-29 22:54:51martin.pantersetmessageid: <1456786491.18.0.00686604672056.issue26404@psf.upfronthosting.co.za>
2016-02-29 22:54:51martin.panterlinkissue26404 messages
2016-02-29 22:54:50martin.pantercreate