This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Socketserver documentation : error in server example
Type: Stage: resolved
Components: Documentation Versions: Python 3.6
process
Status: closed Resolution:
Dependencies: Superseder:
Assigned To: docs@python Nosy List: docs@python, ned.deily, tcolombo
Priority: normal Keywords:

Created on 2018-01-15 16:40 by tcolombo, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (4)
msg309995 - (view) Author: Tristan Colombo (tcolombo) Date: 2018-01-15 16:40
In the documentation, at page :
- https://docs.python.org/3.6/library/socketserver.html
- Section 21.21.4.1

In the server side code :
if __name__ == "__main__":
    HOST, PORT = "localhost", 9999

    # Create the server, binding to localhost on port 9999
    with socketserver.TCPServer((HOST, PORT), MyTCPHandler) as server:
    ...

We got an error line 24 :     
with socketserver.TCPServer((HOST, PORT), MyTCPHandler) as server:
AttributeError: __exit__

socketserver.TCPServer object has no __exit__() method and can not be used in 'with' statement.

Proposed correction :
server = socketserver.TCPServer((HOST, PORT), MyTCPHandler)
with server:
    ...
msg309996 - (view) Author: Tristan Colombo (tcolombo) Date: 2018-01-15 16:43
Correction of my previous correction :
server = socketserver.TCPServer((HOST, PORT), MyTCPHandler)

'with' statement can not be used...
msg309997 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2018-01-15 16:45
In what environment are you trying this?  The example works for me (on a current macOS) system.
msg309998 - (view) Author: Tristan Colombo (tcolombo) Date: 2018-01-15 16:51
Running on Debian Etch
Ok, my python3 was broken and links to python3.5.3
All my apologizes
History
Date User Action Args
2022-04-11 14:58:56adminsetgithub: 76739
2018-01-15 16:51:12tcolombosetstatus: open -> closed

messages: + msg309998
stage: resolved
2018-01-15 16:45:32ned.deilysetnosy: + ned.deily
messages: + msg309997
2018-01-15 16:43:42tcolombosetmessages: + msg309996
2018-01-15 16:40:20tcolombocreate