Python’s ThreadPoolExecutor
doesn’t have the feature you’re looking for, but the provided class can be easily sub-classed as follows to provide it:
from concurrent import futures
import queue
class ThreadPoolExecutorWithQueueSizeLimit(futures.ThreadPoolExecutor):
def __init__(self, maxsize=50, *args, **kwargs):
super(ThreadPoolExecutorWithQueueSizeLimit, self).__init__(*args, **kwargs)
self._work_queue = queue.Queue(maxsize=maxsize)