[Python-Dev] Socket timeout patch

Guido van Rossum guido@python.org
Fri, 07 Jun 2002 00:01:02 -0400

I've more or less completed the introduction of timeout sockets.

Executive summary: after sock.settimeout(T), all methods of sock will
block for at most T floating seconds and fail if they can't complete
within that time.  sock.settimeout(None) restores full blocking mode.

I've also done some long-needed rigorous cleanup of the socket module
source code, e.g. I got rid of the PySock* static names.

Remaining issues:

- A test suite.  There's no decent test suite for the timeout code.
  The file test_timeout.py doesn't test the functionality (as I
  discovered when the test succeeded while I had several blunders in
  the select code that made everything always time out).

- Cross-platform testing.  It's possible that the cleanup broke things
  on some platforms, or that select() doesn't work the same way.  I
  can only test on Windows and Linux; there is code specific to OS/2
  and RISCOS in the module too.

- I'm not sure that the handling of timeout errors in accept(),
  connect() and connect_ex() is 100% correct (this code sniffs the
  error code and decides whether to retry or not).

- Should sock.settimeout(0.0) mean the same as sock.setblocking(0)?
  Currently it sets a timeout of zero seconds, and that behaves pretty
  much the same as setting the socket in nonblocking mode -- but not
  exactly.  Maybe these should be made the same?

- A socket filedescriptor passed to fromfd() is now assumed to be in
  blocking, non-timeout mode.

- The socket.py module has been changed too, changing the way
  buffering is done on Windows.  I haven't reviewed or tested this
  code thoroughly.

I hope some of the developers on this list will help me out with all
this!  In the mean time, many thanks to Michael Gilfix who did most of
the thinking and coding.

--Guido van Rossum (home page: http://www.python.org/~guido/)