python - 处理 pycurl 在 Twitter streaming api 上挂起

标签 python curl twitter pycurl

我正在使用 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()

最佳答案

发件人:http://man-wiki.net/index.php/3:curl_easy_setopt

CURLOPT_LOW_SPEED_LIMIT - Pass a long as parameter. It contains the transfer speed in bytes per second that the transfer should be below during CURLOPT_LOW_SPEED_TIME seconds for the library to consider it too slow and abort.

CURLOPT_LOW_SPEED_TIME - Pass a long as parameter. It contains the time in seconds that the transfer should be below the CURLOPT_LOW_SPEED_LIMIT for the library to consider it too slow and abort.


例子:

conn.setopt(pycurl.LOW_SPEED_LIMIT, 1)
conn.setopt(pycurl.LOW_SPEED_TIME, 90)

关于python - 处理 pycurl 在 Twitter streaming api 上挂起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4960021/

相关文章:

javascript - Python-Requests,如何动态接收url?

Python PyInstaller 和包含图标文件

python urllib2文件发送问题

ruby - Sinatra 不以 twitter gem 开头

c# - 如何向目标用户发送推文?

python - 在Django中获取页面动态标题的好方法是什么?

python - 与 xterm 兼容的 TTY 颜色查询命令?

python - 如何运行 C 程序并使用 Twisted Python 获取程序输出

curl - NTLM 握手被拒绝 : CURL

php - 在 PHP 中模拟启用 cookie 的浏览器