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.
Created on 2012年03月26日 20:53 by gjb1002, last changed 2022年04月11日 14:57 by admin. This issue is now closed.
| Messages (4) | |||
|---|---|---|---|
| msg156869 - (view) | Author: Geoffrey Bache (gjb1002) | Date: 2012年03月26日 20:53 | |
Here I'm referring to the section about RequestHandler objects under the SocketServer page. http://docs.python.org/release/2.7.2/library/socketserver.html#requesthandler-objects This appears to be the same in Python 2.6 and Python 2.7. But the objects don't behave the same, in two respects: 1) For finish() "If setup() or handle() raise an exception, this function will not be called." This is true in Python 2.6. It appears to no longer be true in Python 2.7, where finish() is called in a "finally" clause. 2) For handle(). "The default implementation does nothing". This is true up to a point, but using the default implementation has different effects. Specifically, if I try to read from a socket when the server has not written anything, I get an exception in Python 2.6 and an empty string in Python 2.7. Consider this code: ## server.py from SocketServer import TCPServer, StreamRequestHandler import sys, socket server = TCPServer((socket.gethostname(), 0), StreamRequestHandler) host, port = server.socket.getsockname() address = host + ":" + str(port) print "Started server at", address sys.stdout.flush() server.serve_forever() ## client.py import sys, socket servAddr = sys.argv[1] host, port = servAddr.split(":") serverAddress = (host, int(port)) sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect(serverAddress) sock.sendall("Some Message") sock.shutdown(1) response = sock.makefile().read() print "Got reply:", response sock.close() and compare the following: $ python2.7 server.py & Started server at 127.0.1.1:42759 $ python2.7 client.py 127.0.1.1:42759 Got reply: $ python2.6 server.py & Started server at 127.0.1.1:42758 $ python client.py 127.0.1.1:42758 Traceback (most recent call last): File "client.py", line 12, in <module> response = sock.makefile().read() File "/usr/lib/python2.7/socket.py", line 351, in read data = self._sock.recv(rbufsize) socket.error: [Errno 104] Connection reset by peer (doesn't matter which Python runs the client in the last case) I am unsure whether this is a bug in Python 2.6, or really what the reasoning behind the behaviour difference is, but I think this change in behaviour is worth a small note in the documentation (how it will behave if you try to read when nothing has been written) |
|||
| msg222243 - (view) | Author: Mark Lawrence (BreamoreBoy) * | Date: 2014年07月04日 00:01 | |
@Geoffrey sorry about the delay in getting back to you. |
|||
| msg330412 - (view) | Author: Martin Panter (martin.panter) * (Python committer) | Date: 2018年11月26日 10:17 | |
Regarding the first point, "finish" is no longer called after an exception. This was apparently changed in 2.7.4 (see Issue 14574), but Geoffrey was referring to older documentation. Regarding the second point, about ECONNRESET vs graceful shutdown, this seems to be due to the "shutdown" call added to in "TCPServer.close_request" in Issue 6267. |
|||
| msg367383 - (view) | Author: Zachary Ware (zach.ware) * (Python committer) | Date: 2020年04月27日 04:03 | |
Since Python 2.7 is now at end-of-life, I'm closing the issue. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:57:28 | admin | set | github: 58626 |
| 2020年04月27日 04:03:34 | zach.ware | set | status: open -> closed nosy: + zach.ware messages: + msg367383 resolution: out of date stage: needs patch -> resolved |
| 2018年11月26日 12:01:11 | BreamoreBoy | set | nosy:
- BreamoreBoy |
| 2018年11月26日 10:17:48 | martin.panter | set | nosy:
+ martin.panter messages: + msg330412 |
| 2014年07月04日 00:01:52 | BreamoreBoy | set | nosy:
+ BreamoreBoy, pitrou messages: + msg222243 |
| 2012年03月28日 04:55:29 | eric.araujo | set | stage: needs patch versions: - Python 2.6 |
| 2012年03月26日 20:53:45 | gjb1002 | create | |