【发布时间】:2016-05-19 10:33:51
【问题描述】:
我有一个 Python 程序,它通过 requests 包为每个轮询使用不同的线程并行发送几个(大约 5-6 个)长轮询请求。我意识到我的一些线程有时会冻结。发生这种情况时,我发送请求的服务器没有收到请求。我还为请求设置了超时,但它不起作用。
try:
print("This line prints")
response = requests.head(poll_request_url, timeout=180)
print("This line does not print when freeze occurs")
except ReadTimeout:
print("Request exception.")
except RequestException as e:
print("Request exception.")
except Exception:
print("Unknown exception.")
print("This line does not print either when freeze occurs.")
我在带有 Raspbian OS 的 Raspberry Pi 2 硬件上执行此操作。
当我使用 Python 2.7 时,我使用了相同的程序没有问题。最近我切换到 Python 3.5。我使用 2.8.1 和 2.9.1 的两个请求版本进行了测试。
这个问题发生的频率不是很高,但每天在不同的线程上发生 2-3 次。
可能是什么问题?我该如何调试?
编辑:通过更新 Linux 内核解决了这个问题。
【问题讨论】:
标签: python multithreading python-requests long-polling