python - Python 池多处理请求挂起
问题描述
我的程序中的代码基本上同时执行 10 个 python 请求并同时处理它们的输出,它工作了一段时间,但我改变了一些东西,但无法弄清楚是什么破坏了它。
以下代码是调用的代码,代码似乎在第 3 行和第 4 行之间冻结,因此在执行多线程请求的过程中。
'print("failed to close") 行没有打印出来,似乎表明程序没有到达 pool.close() 指令。
listoftensites = listoftensites
pool = Pool(processes=10) # Initalize a pool of 10 processes
listoftextis, listofonline = zip(*pool.map(onionrequestthreaded, listoftensites)) # Use the pool to run the function on the items in the iterable
print("failed to close ")
pool.close()
# this means that no more tasks will be added to the pool
pool.join()
它挂起时调用的函数紧跟在'print(“failed in return”)'行之后,这似乎表明请求没有正确终止并返回预期值。
def onionrequestthreaded(onionurl):
session = requests.session()
session.proxies = {}
session.proxies['http'] = 'socks5h://localhost:9050'
session.proxies['https'] = 'socks5h://localhost:9050'
onionurlforrequest = "http://" + onionurl
#print(onionurlforrequest)
print("failed with proxy session")
try:
print("failed in request")
r = session.get(onionurlforrequest, timeout=15, allow_redirects=True)
online = 2
print("failed in text extraction")
textis = r.text
except:
print("failed in except")
#print("failed")
online = 1
textis = ""
print("failed in return")
return textis, online
非常令人困惑,但我可能正在做一些简单的事情。请让我知道是否有解决方案,因为我正在拔头发。
解决方案
推荐阅读
- amazon-web-services - Kubernetes 节点的跨账户 ECR 访问
- javascript - 如何使反应引导工具提示适合容器?
- timezone - TimeZone.init(identifier:"") 和 TimeZone(abbreviation: "") 有什么区别?
- javascript - 单击选项卡中的下一步按钮时的下划线移动
- python - Qt HTML 子集——可能的未记录限制
- node.js - 在nodejs中返回未定义的模块函数
- r - 在 R 中运行带有子组的 ANOVA
- tabulator - 制表符表格中的箭头和文本框出现方向错乱
- c# - 使用逗号作为小数分隔符
- python - 为什么不是所有的二元组都在 gensim 的“短语”工具中创建?