2

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?

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Indeed, by looking at ProcessExplorer's Threads panel it seems that the max_workers is always honored. Thank you :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.