[issue5293] socket timeouts even in blocking mode
Martin v. Löwis
report at bugs.python.org
Wed Feb 18 00:25:19 CET 2009
Martin v. Löwis <martin at v.loewis.de> added the comment:
> Isn't it a job of crossplatform programming language to abstract from
> low-level platform details?
It's certainly not Python's job. It's an explicit design goal, and a
long tradition, to expose system interfaces *as is*, with the very
same parameters, and the very same error codes. This is useful for
developers who need to understand what problem they encounter - they
can trust that Python doesn't second-guess the operating system.
It might be useful to put a layer on top of the system interfaces,
but such a layer needs to use different names.
> The scope of this bug is not about handling all possible Winsock errors.
> It is about proper handling the sole timeout error from the list
> http://www.winsock-error.com/ to make socket.connect() interface
> consistent for both windows and linux.
That's nearly impossible, with respect to specific error conditions.
The TCP stacks are too different.
You can easily define an common (but useless) error handling scheme
yourself: catch Exception, and interpret it as "it didn't work".
> BTW, I have tested the behaviour on linux - the system timeout on socket
> does occur, but with different error code.
> socket.error: (110, 'Connection timed out')
> Note that the error message is different too. That means that to
> properly wait for service to appear (or retry to reconnect later if
> server is not available) you need to handle three error cases.
That's correct. However, you shouldn't look at the error message when
handling the error on Linux. Instead, you should check whether the
error code is errno.ETIMEDOUT. The error message is only meant for
a human reader. Also notice that possible other errors returned from
connect are EACCES, EPERM, EADDRINUSE, EAFNOSUPPORT, EAGAIN,
EALREADY, EBADF, ECONNREFUSED, EFAULT, EINPROGRESS, EINTR, EISCONN,
Python tracker <report at bugs.python.org>
More information about the Python-bugs-list