title: Best way to constantly request http data?
body: <p>Which is the best way to request constant data from a server in Python? I've tried with Urllib3 but for some reason after a while the python script stops. And I am also trying urllib2 (see below the code), but I notice there's a huge delay sometimes (that did not happen as frequently with urllib3) and the response is not every 0.5 seconds (sometimes it's every 6 seconds). What can I do to solve this?</p>
  
  <pre><code>import socket
  import urllib2
  import time
  
  # timeout in seconds
  timeout = 10
  socket.setdefaulttimeout(timeout)
  
  while True:
      try:
          # this call to urllib2.urlopen now uses the default timeout
          # we have set in the socket module
          req = urllib2.Request('https://www.okcoin.com/api/v1/future_ticker.do?symbol=btc_usd&amp;contract_type=this_week')
          response = urllib2.urlopen(req)
          r = response.read()
  
          req2 = urllib2.Request('http://market.bitvc.com/futures/ticker_btc_week.js')
          response2 = urllib2.urlopen(req2)
          r2 = response2.read()
      except:
          continue
  
      print r + str(time.time())
      print r2 + str(time.time())
      time.sleep(0.5)
  </code></pre>