title: Handle pycurl hang on Twitter streaming api
body: <p>I am using pycurl to connect to the twitter streaming API.</p>
  
  <p>This works well but sometimes after running for a few hours it will stop hang indefinitely, not throwing any exceptions. How can I detect/handle a hang in this script?</p>
  
  <pre><code>import pycurl, json
  
  STREAM_URL = "http://stream.twitter.com/1/statuses/filter.json"
  
  USER = "presidentskroob"
  PASS = "12345"
  
  def on_receive(data):
    print data
  
  conn = pycurl.Curl()
  conn.setopt(pycurl.USERPWD, "%s:%s" % (USER, PASS))
  conn.setopt(pycurl.URL, STREAM_URL)
  conn.setopt(pycurl.WRITEFUNCTION, on_receive)
  conn.perform()
  </code></pre>