[Python-bugs-list] [ python-Bugs-708927 ] socket timeouts produce wrong errors in win32

SourceForge.net noreply@sourceforge.net
Mon, 24 Mar 2003 09:59:37 -0800


Bugs item #708927, was opened at 2003-03-24 08:59
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=708927&group_id=5470

Category: Python Library
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Greg Chapman (glchapman)
Assigned to: Nobody/Anonymous (nobody)
Summary: socket timeouts produce wrong errors in win32

Initial Comment:
Here's a session:

Python 2.3a2 (#39, Feb 19 2003, 17:58:58) [MSC v.1200 
32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more 
information.
>>> import socket
>>> socket.setdefaulttimeout(0.01)
>>> import urllib
>>> urllib.urlopen('http://www.python.org')
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "c:\Python23\lib\urllib.py", line 76, in urlopen
    return opener.open(url)
  File "c:\Python23\lib\urllib.py", line 181, in open
    return getattr(self, name)(url)
  File "c:\Python23\lib\urllib.py", line 297, in open_http
    h.endheaders()
  File "c:\Python23\lib\httplib.py", line 705, in endheaders
    self._send_output()
  File "c:\Python23\lib\httplib.py", line 591, in 
_send_output
    self.send(msg)
  File "c:\Python23\lib\httplib.py", line 558, in send
    self.connect()
  File "c:\Python23\lib\httplib.py", line 798, in connect

IOError: [Errno socket error] (2, 'No such file or directory')
>>> urllib.urlopen('http://www.python.org')
< SNIP >

IOError: [Errno socket error] (0, 'Error')

Looking at socketmodule.c, it appears internal_connect 
must be taking the path which (under MS_WINDOWS) 
calls select to see if there was a timeout.  select must 
be returning 0 (to signal a timeout), but it apparently 
does not call WSASetLastError, so when set_error is 
called, WSAGetLastError returns 0, and the ultimate 
error generated comes from the call to 
PyErr_SetFromErrNo.  Perhaps in this case 
internal_connect should itself call WSASetLastError 
(with WSAETIMEDOUT rather than 
WSAEWOULDBLOCK?).

The reason I ran into this is I was planning to convert 
some code which used the timeoutsocket module under 
2.2.  That module raises a Timeout exception (which the 
code was catching) and I was trying to figure out what 
the equivalent exception would be from the normal 
socket module.  Perhaps the socket module should 
define some sort of timeout exception class so it would 
be easier to detect timeouts as opposed to other socket 
errors.


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=708927&group_id=5470