Python多线程/线程池创建

代码如下

def exp(url):
    timeout = time.time()
    print(url + "  " + timeout)

def run(filename,pools=5):
    works = []
    with open(filename, "r") as f:
        for i in f:
            target_url = [i.rstrip()]
            works.append((target_url, None))
    pool = threadpool.ThreadPool(pools)
    reqs = threadpool.makeRequests(exp, works)
    [pool.putRequest(req) for req in reqs]
    pool.wait()

if __name__ == '__main__':
    run("fofa.result.txt", 20)
赞(0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址