title: Read timeout using either urllib2 or any other http library
body: <p>I have code for reading an url like this:</p>
  
  <pre><code>from urllib2 import Request, urlopen
  req = Request(url)
  for key, val in headers.items():
      req.add_header(key, val)
  res = urlopen(req, timeout = timeout)
  # This line blocks
  content = res.read()
  </code></pre>
  
  <p>The timeout works for the urlopen() call. But then the code gets to the res.read() call where I want to read the response data and the timeout isn't applied there. So the read call may hang almost forever waiting for data from the server. The only solution I've found is to use a signal to interrupt the read() which is not suitable for me since I'm using threads.</p>
  
  <p>What other options are there? Is there a HTTP library for Python that handles read timeouts? I've looked at httplib2 and requests and they seem to suffer the same issue as above. I don't want to write my own nonblocking network code using the socket module because I think there should already be a library for this. </p>
  
  <p><strong>Update:</strong> None of the solutions below are doing it for me. You can see for yourself that setting the socket or urlopen timeout has no effect when downloading a large file:</p>
  
  <pre><code>from urllib2 import urlopen
  url = 'http://iso.linuxquestions.org/download/388/7163/http/se.releases.ubuntu.com/ubuntu-12.04.3-desktop-i386.iso'
  c = urlopen(url)
  c.read()
  </code></pre>
  
  <p>At least on Windows with Python 2.7.3, the timeouts are being completely ignored.</p>