title: Python: how to distinguish between socket error and timeout?
body: <p>I'm having the following code:</p>
  
  <pre><code>try:
      while 1:
          s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
          s.settimeout(5);
          s.connect((HOST,PORT))
          print("before send")
          #time.sleep(10);
          #s.sendall('GET / HTTP/1.1\r\nConnection: Keep-Alive\r\nHost: www.google.lt\r\n\r\n')
          data=s.recv(52)
          print("after send");
          s.close()
          if string.find(data,"HTTP/1.1 200 OK") == -1:
              print("Lost Connection")
          print(data)
          time.sleep(2)
  except KeyboardInterrupt:
      print("CTRL C occured")
  except socket.error:
      print("socket error occured: ")
  except socket.timeout:
      print("timeout error")
  </code></pre>
  
  <p>I have commented the sendall function to test how recv generates timeout exception.
  But the problem is that i get socket.error exception.
  If i change the last lines of code to:</p>
  
  <pre><code>except socket.timeout:
      print("timeout error")
  except socket.error:
       print("socket error occured: ")
  </code></pre>
  
  <p>Then i get socket.timeout exception.
  So what exception is really generated?</p>