PyCurl的默认超时时间是多少

4 投票
1 回答
10182 浏览
提问于 2025-04-17 15:07

我觉得这个问题的标题已经很清楚了,所以你可能不需要继续读下去,不过我还是说一下:

我已经用PyCurl工作了一段时间,通常我都是通过下面的方式来设置超时时间:

curlConnector = pycurl.Curl()
curlConnector.setopt(pycurl.CONNECTTIMEOUT, 30)

但是我开始想知道默认的超时时间是多少,或者怎么找到这个信息,到现在为止我还没有看到满意的答案。如果我不手动指定超时时间,默认的超时时间是什么呢?是来自socket的设置吗?(顺便说一下,我是在Ubuntu 12.04和python2.7上工作的)

1 个回答

7

我下载了PyCurl。在压缩包的doc/文件夹里,有几个文档文件。其中一个是doc/curlobject.html,上面提到setup和libcurl里的curl_easy_setopt对应。点击那个链接,你会看到一个页面,地址是http://curl.haxx.se/libcurl/c/curl_easy_setopt.html,在页面上搜索'CONNECTTIMEOUT',你会发现:

CURLOPT_CONNECTTIMEOUT

Pass a long. It should contain the maximum time in seconds that you allow the connection to the server to take. 
This only limits the connection phase, once it has connected, this option is of no more use. 
Set to zero to switch to the default built-in connection timeout - 300 seconds. 
See also the CURLOPT_TIMEOUT option.

所以,我可以说默认的超时时间是300秒。

撰写回答