title: DNS timeout on 'requests' python library
body: <p>For my project, I have to check the status of a website (on a shared hosting).</p>
  
  <p>I use Python requests library.</p>
  
  <pre><code>def getStatusCode(url):
      try:
          return requests.head(url,timeout=0.3).status_code
      except:
          return -1
  </code></pre>
  
  <p>This code works great under MacOS 10.10 with Python3.4 with an url like <a href="http://www.google.com" rel="nofollow noreferrer">http://www.google.com</a>. If I unplug my ISP cable, I immediately got an exception. </p>
  
  <p>Under Ubuntu Server 14.04 with Python3.4, if I unplug my ISP cable, I never get a timeout error. Same problem on Raspbian.</p>
  
  <p>After some tests, if I replace the url with an IP <a href="http://216.58.212.100" rel="nofollow noreferrer">http://216.58.212.100</a>, Ubuntu Server raise me an exception, but as I'm on a shared web hosting so I can't use an IP. </p>
  
  <p>After some research I found there is a difference between timeout in requests library and DNS lookup that not performed by it but by the OS.</p>
  
  <p>So my question is what is the most beautiful way to solve this ? Do I need to add extra timeout exception in Python like : <a href="https://stackoverflow.com/questions/492519/timeout-on-a-python-function-call">Timeout on a function call</a></p>
  
  <p>Thank you</p>