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.