Martin Panter added the comment:
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.
----------
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue26404>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com