python - 调用 requests.get(...) 随机杀死线程。为什么?
问题描述
我有一个Python 2.7 脚本,我在其中requests.get(...)
以顺序方式对许多服务器进行 GET 调用。但是,有时,我正在拨打电话的线程在拨打电话时会被杀死requests.get(...)
,我不知道为什么。我知道这一点是因为我在拨打电话之前和之后打印了日志,并且最后一个日志条目始终是拨打电话之前的那个。使用以下命令进行调用:
r = requests.get("http://" + node.hostname + ":2082/api/config", timeout=1)
这是进行调用的方法的基本框架:
def refresh_current_configs(number):
while True:
try:
for node in nodes:
try:
r = requests.get("http://" + node.hostname + ":2082/api/config", timeout=1)
except (ConnectionError, requests.exceptions.Timeout) as e:
unreachable_nodes.add(node.hostname)
continue
# Do processing
except Exception,e:
logger.error(e + " -- " + str(number))
time.sleep(1000)
这就是我创建一个在refresh_current_configs
主线程中运行方法的线程的方式:
consumer = threading.Thread(target=refresh_current_configs,args=(number,),name='config_refresher')
consumer.start()
任何想法为什么调用requests.get(...)
会随机杀死进行调用的线程?
解决方案
推荐阅读
- swift - CollectionViewCell 未显示从 Firebase 接收数据
- python-3.x - 如何在 Sanic 中使用依赖注入实现 CORS
- sql - 在值为零的情况下返回标称值时出错
- laravel - laravel 有没有办法在 handle 方法中手动完成工作?
- java - 如何将 Java 列表映射转换为 Scala 列表映射
- python - 根据列表值列表创建 Python 列
- c# - 如何将一个列表添加到 C# 中的另一个列表中?
- angularjs - 如何使用 angularjs 在谷歌组织结构图中添加样式?
- c# - 指针重置一次方法调用第二次
- javascript - 如何从 Bing Maps V8 获取路线货币成本