2012-02-13 134 views
2

我使用concurrent.futures'类ThreadPoolExecutor在web服务上进行压力测试。ThreadPoolExecutor内部结构

据我所知,构造函数参数告诉执行程序池中最大线程数是多少。无论如何,是否有任何保证,这将是有效使用的数字,或者它可能会比那更少(例如,由于某些硬件限制)?

如果是这样,有没有办法知道有多少工作线程将被有效实例化?

回答

2

从DOC

Args: 
     max_workers: The maximum number of threads that can be used to 
      execute the given calls. 

从代码,_adjust_thread_count(),看来新线程上创建的需求,并通过max_workers限制。

if len(self._threads) < self._max_workers: 
     t = threading.Thread(target=_worker, 
          args=(weakref.ref(self, weakref_cb), 
            self._work_queue)) 

也似乎len(self._threads)是为有效实例化。

+0

事实上,通过查看ProcessExplorer的主题面板,似乎max_workers始终得到尊重。谢谢 :) – Simone 2012-02-13 10:59:52