小编Ant*_*kau的帖子

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()
Run Code Online (Sandbox Code Playgroud)

它首先起作用,但后来出了点问题。所有 20 个线程都处于活动状态,但随后它们什么也不做。我可以在 htop 中看到它们还活着,但实际上我不明白为什么什么也没发生。

任何想法可能是错误的?

python request threadpoolexecutor concurrent.futures

6
推荐指数
1
解决办法
2958
查看次数

在Python中从bytestring创建zip文件对象?

我有一个字节串.它保证它是以字节为单位的zip文件的表示.我怎么能用Python创建一个zip文件对象,知道这个字节串?

python zip base64 decode python-3.4

4
推荐指数
1
解决办法
5935
查看次数