Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
有没有办法使用Python workerpool模块创建一个池池?_Python_Multithreading_Threadpool_Pool - Fatal编程技术网

有没有办法使用Python workerpool模块创建一个池池?

有没有办法使用Python workerpool模块创建一个池池?,python,multithreading,threadpool,pool,Python,Multithreading,Threadpool,Pool,我正在使用workerpool模块创建一些线程来执行HTTP访问服务器。到目前为止,我喜欢这个概念。我为URL列表设置了一个下载作业,然后将该作业分配给一个线程池。到目前为止还不错 import urllib3 import workerpool from urllib3 import HTTPConnectionPool headers = { } headers['user-agent'] = 'Python-httplib2/0.7.4 (gzip)' headers['accept-e

我正在使用workerpool模块创建一些线程来执行HTTP访问服务器。到目前为止,我喜欢这个概念。我为URL列表设置了一个下载作业,然后将该作业分配给一个线程池。到目前为止还不错

import urllib3
import workerpool
from urllib3 import HTTPConnectionPool

headers = { }
headers['user-agent'] = 'Python-httplib2/0.7.4 (gzip)'
headers['accept-encoding'] = 'gzip, deflate'

class Download_Dashlet_Job(workerpool.Job):
  "This is a download dashlet Job object for downloading a given URL."
  def __init__(self, url):
    self.url = url
  def run(self):
    request = tcp_pool.request('GET', self.url, headers=headers)

#Create a pool of TCP connections for communication to the server (this is using urllib3)
tcp_pool = HTTPConnectionPool('M_Server3', port=8080, timeout=None, maxsize=3, block=True)

# Initialize a pool of three dashlet worker threads to be used for downloading from a page
dashlet_thread_worker_pool = workerpool.WorkerPool(size=3)

# urls.txt is just a text file with 5 urls in it
for url in open("urls.txt"):
  job = Download_Dashlet_Job(url.strip())
  dashlet_thread_worker_pool.put(job)

# Send shutdown jobs to all dashlet worker threads
dashlet_thread_worker_pool.shutdown()
dashlet_thread_worker_pool.wait()
上面的代码运行良好,但它只有一个线程池。所以,情况是

单用户打开Firefox到yahoo,浏览器启动多个线程从yahoo页面下载组件

我现在想做的是

十个用户向雅虎开放他们的浏览器,每个用户都有自己的ie线程池从雅虎页面下载

我被困在这一点上了。我是否需要为用户创建一个类对象,然后该对象调用对象下载\u Dashlet\u作业


我试图那样做,但我完全搞砸了。使用workerpool应该不会很难,对吗

为什么这十个用户不能共享池?如果你游得够深,他们都会游泳。是的,没错。我可以为这10个用户添加很多线程到池中。我想我的问题真的是tcp_池。maxSize是3个套接字,但我需要为10个用户中的每个用户提供3个套接字,而不是总共3个的全局设置。如何将tcp_池从作业中移动到用户?