Pregunta

import pycurl

pycurl.version
# libcurl/7.29.0 GnuTLS/2.12.23 zlib/1.2.7 libidn/1.25 librtmp/2.3

c = pycurl.Curl()
c.setopt(pycurl.TIMEOUT_MS, 1000)
c.setopt(pycurl.URL, 'http://example.com/')
c.perform()
# ok

c = pycurl.Curl()
c.setopt(pycurl.URL, 'http://example.com/')
c.setopt(pycurl.TIMEOUT_MS, 999)
c.perform()
# pycurl.error: (28, '')

c = pycurl.Curl()
c.setopt(pycurl.URL, 'http://example.com/')
c.setopt(pycurl.TIMEOUT_MS, 999)
c.setopt(pycurl.NOSIGNAL, 1)
c.perform()
# ok again

Can someone explain why the timeout less than 1 second failed and nosignal make it work again?

¿Fue útil?

Solución 2

Accoding to libcurl API, timeout_ms < 1000 is not allowed when using standard name resolver.

CURLOPT_TIMEOUT_MS

An alternative to CURLOPT_TIMEOUT but takes number of milliseconds instead. If libcurl is built to use the standard system name resolver, that portion of the transfer will still use full-second resolution for timeouts with a minimum timeout allowed of one second.

Otros consejos

I assume it is because some library calls that CURL does, like for example DNS lookups, do not support timeouts. Therefore, the only way to interrupt them is by setting up a signal.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top