gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 14:34:08 26 4
gpt4 key购买 nike

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

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com