문제

I'm using concurrent.futures' class ThreadPoolExecutor to do stress testing on a webservice.

As far as I can understand, the max_workers constructor parameters tell the executor what's the maximum number of threads that will be in the pool. Anyway, is there any guarantee that that's the number that will be effectively used, or it could be lesser (for example, due to some hardware limitation) than that?

If so, is there a way to know how many worker threads will be effectively instantiated?

도움이 되었습니까?

해결책

from the doc

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

from the code, _adjust_thread_count(), seems the new thread is created on demand and limited by max_workers.

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

also seems len(self._threads) is for the effectively instantiated.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top