[Python-Dev] I vote to reject: Adding timeout to socket.py and httplib.py.

Alan Kennedy python-dev at alan.kennedy.name
Wed Mar 21 14:10:20 CET 2007


[Facundo]
> Voting is open, ;)

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?
I have one more issue with the patch.
I think that the exception handling in the function is wrong. This is
(approximately) the way the patch is currently defined.
def create_connection(address, **kwargs):
 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 socket
 except error, err:
 msg = str(err) # <-- don't do this
 if sock is not None:
 sock.close()
 raise error(msg)
Changing the exception to with msg = str(err) is the wrong thing to
do: this will hide the exception and make comparisons with symbolic
constants fail, for users that want to handle exceptions.
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")
[Facundo]
> Or it's just denial towards this patch?

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.
Sorry.
Alan.


More information about the Python-Dev mailing list

AltStyle によって変換されたページ (->オリジナル) /