我正在使用 pycurl 连接到 twitter 流 API。
这很好用,但有时在运行几个小时后它会无限期地停止挂起,不会抛出任何异常。如何检测/处理此脚本中的挂起?
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()