The socket timeout patch is finally available with doc updates n' unit test as patch #555085 in the SF tracker. This implementation provides timeout functionality at the C level. A patch to socket.py also fixes the problem of losing data while an exception is thrown to the underlying socket.
Hi Michael,
Sorry for taking such a long time to review this. (Apparently nobody
else had time either.) And thanks for doing this! I think this is a
great start. Rather than typing them in the SF bug manager issue I am
mailing them (I'll add a link to the archived version of this message
to the SF bug manager to track the activity).
General style nits:
- You submitted a reverse diff! Customary is diff(old, new).
- Please don't put a space between the function name and the open
parenthesis. (You do this both in C and in Python code.)
- Also please don't put a space between the open parenthesis and the
first argument (you do this almost consistently in test_timeout.py).
- Please don't introduce lines longer than 78 columns.
Feedback on the patch to socket.py:
- I think you're changing the semantics of unbuffered and
line-buffered reads/writes on Windows. For one thing, you no longer
implement line-buffered writes correctly. The idea is that if the
buffer size is set to 1, data is flushed at \n only, so that if
the code builds up the line using many small writes, this doesn't
result in many small sends. There was code for this in write() --
why did you delete it?
- It also looks like you've broken the semantics of size<0 in read().
- Maybe changing the write buffer to a list makes sense too?
- Since this code appears independent from the timeoutsocket code,
maybe we can discuss this separately?
Feedback on the documentation:
- I would document that the argument to settimeout() should be int or
float (hm, can it be a long? that should be acceptable even if it's
strange), and that the return value of gettimeout() is None or a
float.
- You may want to document the interaction with blocking mode.
Feedback on the C socket module changes:
- Why import the select module? It's much more efficient to use the
select system call directly. You don't need all the overhead and
generality that the select module adds on top of it, and it costs a
lot (select allocates lots of objects and lots of memory and hence
is very expensive).
-