[Python-Dev] Adding timeout to socket.py and httplib.py
Alan Kennedy
python-dev at alan.kennedy.name
Tue Mar 20 18:17:23 CET 2007
[Facundo]
> But, I recognize that maybe it's [connect] not the best name. What about
> "create_connection"?
I have no strong feelings about it, other than to say it should not be
"connect". How about
* connect_to_server()
* open_connection()
* open_client_connection()
There's no need to include "timeout" in the name, IMO.
[Alan]
>> Another question I would ask is: "How do I ensure that my newly
>> created connected client socket is in blocking mode, *without* making
>> any assumptions about the value of socket.getdefaulttimeout()?"
[Facundo]
> Call like this:
>
> newsock = socket.connect((..., ...))
> newsock.setblocking(1)
Ah, but it's too late by the time the socket.connect call returns: the
timeout/blocking behaviour of the socket.connect call is the very
thing we're trying to control.
Whenever I look at the proposed API, I think: What happens when the
socket.connect call is preceded by a call which changes the default
socket timeout/blocking behaviour, e.g.
socket.setdefaulttimeout(1)
newsock = socket.connect(HOST, PORT, None) # <-- None param ignored
newsock.setblocking(1) # <-- This does not affect the behaviour of the connect
I.E. I do not get the blocking behaviour I want. The proposed API does
not permit me to get blocking behaviour by specifying a timeout value
of None.
Whereas with the slightly modified API I suggested earlier, it simply becomes
socket.setdefaulttimeout(1)
newsock = socket.connect(HOST, PORT, timeout=None)
# newsock.setblocking(1) # <-- No longer relevant
Regards,
Alan.
More information about the Python-Dev
mailing list