The new settimeout feature for sockets is great, but
the exception that is raised on timeout, socket.error,
is not very helpful. It's not
possible to write code which catches and deals with
timeouts as opposed to the multitude of other socket
errors.
Even looking at the additional detail isn't helpful,
because you get errnos like EINPROGRESS or EAGAIN,
because the socket code doesn't deal with timeouts
explicitly when it selects. Rather, it just lets the
internal_select() return, and then you get an error
when whatever was doing the waiting tries to do its
operation.
I propose that a new exception:
class socket.timeout(socket.error):
pass
be created, and raised whenever the internal_select
times out (i.e. select() returns 0).
This lets applications catch socket.timeout
specifically if they want to, but also allows existing
code to catch socket.error and get all socket-related
exceptions.
|