Am I misusing socket.setdefaulttimeout here?
Skip Montanaro
skip at pobox.com
Thu Mar 20 12:57:17 EST 2003
Socket timeouts are available in 2.3. I'm trying to use them to check URLs
on a couple web servers without hanging indefinitely due to downed servers:
#!/usr/bin/env python
import socket
import urllib2
import sys
TIMEOUT = 30.0
socket.setdefaulttimeout(TIMEOUT)
f = urllib2.urlopen("http://www.mojam.com/")
data = f.read()
When I execute the above, it returns immediately (that is, not 30 seconds
later) with this traceback:
Traceback (most recent call last):
File "chksrvrs.py", line 11, in ?
data = f.read()
File "/Users/skip/local/lib/python2.3/httplib.py", line 1155, in read
return s + self._file.read()
IOError: [Errno 35] Resource temporarily unavailable
Do I misunderstand something about socket timeouts or do they not play well
with urllib and friends (I tried both urllib and urllib2).
Thx,
Skip
More information about the Python-list
mailing list