python – ThreadPoolExecutor请求==死锁?
作者:互联网
我有一个很小的愚蠢的代码,这对谷歌搜索服务提出了很多要求
from concurrent.futures import ThreadPoolExecutor
import requests
import requests.packages.urllib3
requests.packages.urllib3.disable_warnings()
def check(page):
r = requests.get('https://www.google.ru/#q=test&start={}'.format(page * 10))
return len(r.text)
import time
def main():
for q in xrange(30):
st_t = time.time()
with ThreadPoolExecutor(20) as pool:
ret = [x for x in pool.map(check, xrange(1,1000))]
print time.time() - st_t
if __name__ == "__main__":
main()
它首先起作用,但后来出了问题.所有20个线程都存活,但后来它们什么也没做.我可以在htop看到它们还活着,但实际上我不明白为什么没有发生.
什么想法可能是错的?
解决方法:
好像,答案就在那里.
https://github.com/kennethreitz/requests/issues/2649
https://github.com/kennethreitz/requests/issues/2925
标签:python,request,threadpoolexecutor,concurrent-futures 来源: https://codeday.me/bug/20190706/1393063.html