Demian Brecht added the comment:

> Thanks for helping with this Demian. 
No worries. This textual white boarding exercise has also been greatly
valuable in getting my own head wrapped around various low frequency
socket level errors that can be encountered when using the client. The
downside is that this issue is now quite likely very difficult for new
readers to follow :/

> The idea of raising the same exception in all cases is new to me.
This initially puzzled me. I then re-read my response and realized that
I was thinking one thing and wrote another. The exception that I was
intending to suggest using here is ConnectionResetError, rather than the
ConnectionError base class. To elaborate a little further, as I
understand it, the /only/ case where the empty read happens is when the
remote connection has been closed but where the TCP still allows for EOS
to be read. In this case, the higher level implementation (in this case
the client) /knows/ that the empty line is signifying that the
connection has been closed by the remote host.

To be clear, a rough example of what I'm proposing is this:

diff -r e548ab4ce71d Lib/http/client.py
--- a/Lib/http/client.py        Mon Feb 09 19:49:00 2015 +0000
+++ b/Lib/http/client.py        Wed Feb 11 06:04:08 2015 -0800
@@ -210,7 +210,7 @@
         if not line:
             # Presumably, the server closed the connection before
             # sending a valid response.
-            raise BadStatusLine(line)
+            raise ConnectionResetError
         try:
             version, status, reason = line.split(None, 2)
         except ValueError:

Your example of the XML-RPC client would then use the alternative approach:

try:
    return self.single_request(...)
except ConnectionError:
    #retry request once if cached connection has gone cold
    return self.single_request(...)

That all said, I'm also not tremendously opposed to the introduction of
the ConnectionClosed exception. I simply wanted to explore this thought
before the addition is made, although the comments in my patch review
would still hold true.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue3566>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to