[Python-Dev] I vote to reject: Adding timeout to socket.py and httplib.py.
Facundo Batista
facundo at taniquetil.com.ar
Wed Mar 21 14:44:48 CET 2007
Alan Kennedy wrote:
> So what are we voting on exactly? The patch as it currently is? The
> patch has not been updated to reflect recent discussions on the list.
> Will the patch be updated before the vote?
The voting is on a, b or c.
The patch will be updated after I know what python-dev want to do.
> The correct way to handle
>
> 1. An empty return from getaddrinfo()
> 2. Other socket errors
>
> is as follows
>
> def create_connection(address, **kwargs):
> host, port = address
> for res in getaddrinfo(host, port, 0, SOCK_STREAM):
> af, socktype, proto, canonname, sa = res
> sock = None
> try:
> [snip]
> return new_socket
> except error, err:
> if sock is not None:
> sock.close()
> raise err
> else:
> raise error("getaddrinfo returns an empty list")
Wrong! You're raising an error the first time you can not connect. Your
way, the for is superfluous. You're changing functionality here...
See? It's not so easy.
Maybe I should correct the patch like this:
msg = "getaddrinfo returns an empty list"
host, port = address
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
af, socktype, proto, canonname, sa = res
sock = None
try:
[snip]
return sock
except error, msg:
if sock is not None:
sock.close()
raise error, msg
Problems with this approach:
- It raises an exception "the old way"
- If you try to create three sockets, and all with errors, you'll
only see the last one.
Why I think that this is the way to go:
- Because you're not changing the semantics of the function.
Right now it's like this, and maybe we break some code if we change it.
> I think this patch is poorly designed and poorly implemented. There
> are multiple problems in its 17 lines of socket module code; every
> time I look I find a new problem.
It's better than yours. Talk is cheap.
Regards,
--
. Facundo
.
Blog: http://www.taniquetil.com.ar/plog/
PyAr: http://www.python.org/ar/
More information about the Python-Dev
mailing list