title: reading a stream made by urllib2 never recovers when connection got interrupted
body: <p>While trying to make one of my python applications a bit more robust in case of connection interruptions I discovered that calling the read function of an http-stream made by urllib2 may block the script forever. </p>
  
  <p>I thought that the read function will timeout and eventually raise an exception but this does not seam to be the case when the connection got interrupted during a read function call.</p>
  
  <p>Here is the code that will cause the problem:</p>
  
  <pre><code>import urllib2
  
  while True:
      try:
          stream = urllib2.urlopen('http://www.google.de/images/nav_logo4.png')
          while stream.read(): pass
          print "Done"
      except:
          print "Error"
  </code></pre>
  
  <p>(If you try out the script you probably need to interrupt the connection several times before you will reach the state from which the script never recovers)</p>
  
  <p>I watched the script via Winpdb and made a screenshot of the state from which the script does never recover (even if the network got available again). </p>
  
  <p><a href="http://img10.imageshack.us/img10/6716/urllib2.jpg">Winpdb http://img10.imageshack.us/img10/6716/urllib2.jpg</a></p>
  
  <p>Is there a way to create a python script that will continue to work reliable even if the network connection got interrupted? (I would prefer to avoid doing this inside an extra thread.)</p>