为什么请求超时挂起请求?

时间:2017-01-18 11:16:23

标签: python python-3.x python-requests

我有一个程序可以在多个线程中查询一系列API。对于两个API(我无法控制),它发生了线程冻结 - 可能是在HTTP请求上(我有一个警告,告诉我一段时间没有完成调用)。

我最初认为这是timeout的问题,但我的代码处理这个问题,包括捕获异常:

 while True:
    try:
        r = requests.get('http://10.10.10.1', timeout=10)
        if not r.ok:
            raise ValueError('wrong reply for API xxx: {t}, code: {c}'.format(t=r.text, c=r.status_code))
    except Exception as e:
        # cannot reach the API at all
        log.error('problem with API xxx: {e}'.format(e=e))
    else:
        (...)

    time.sleep(10)

考虑到这一点,requests呼叫是否有理由挂起? (requests 2.12.4,Python 3.4+)。 (...)下的代码部分由非常基本的非阻塞数据转换组成。

0 个答案:

没有答案