python3.5使用threadpool的一个问题

import os
import re
import urllib.parse
import urllib.request

import threadpool


def download_file(url):
    print("Begin download {}".format(url))
    urlhandler = urllib.request.urlopen(url)
    p = urllib.parse.urlparse(url).path
    fname = os.path.basename(re.findall(r"item/(.*?)\W", p, re.S)[0]) + ".html"
    with open(fname, 'wb') as f:
        while True:
            chunk = urlhandler.read(1024)
            if not chunk:
                break
            f.write(chunk)


def main():
    urls = [r"http://baike.baidu.com/item/wiki/97755",
            r"http://baike.baidu.com/item/Biosteel?fr=Biosteel",
            r"http://baike.baidu.com/item/HTML/"]
    # 创建大小为2的线程池
    pool_size = 2
    pool = threadpool.ThreadPool(pool_size)
    # 创建工作请求
    requests = threadpool.makeRequests(download_file, urls)
    [pool.putRequest(req) for req in requests]
    # 将具体的请求放入线程池
    print("putting request to pool")
    pool.putRequest(threadpool.WorkRequest(download_file, args=[r"http://baike.baidu.com/item/duang/16824760",]))
    # 处理任务队列中的新请求
    pool.poll()
    pool.wait()

    print("destory all threads before exit...")
    pool.dismissedWorkers(pool_size, do_join=True)


if __name__ == '__main__':
    main()

代码如上所示,在Python3.5的运行报错:

pool.dismissedWorkers(pool_size, do_join=True)
TypeError: 'list' object is not callable

请问一下是哪里错了,应该怎么修改呢?

不负相思意
浏览 627回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python