diff -r 84d752c3ab6f Doc/library/concurrent.futures.rst --- a/Doc/library/concurrent.futures.rst Sat Feb 25 00:47:08 2012 +0100 +++ b/Doc/library/concurrent.futures.rst Mon Feb 27 15:00:14 2012 -0800 @@ -114,10 +114,12 @@ executor.submit(wait_on_future) -.. class:: ThreadPoolExecutor(max_workers) +.. class:: ThreadPoolExecutor(max_workers, queue_size=0) An :class:`Executor` subclass that uses a pool of at most *max_workers* - threads to execute calls asynchronously. + threads to execute calls asynchronously. Parameter *queue_size* is used to + initialize an internal work queue object. If a non-positive number is given, + this queue is unbounded. .. _threadpoolexecutor-example: diff -r 84d752c3ab6f Lib/concurrent/futures/thread.py --- a/Lib/concurrent/futures/thread.py Sat Feb 25 00:47:08 2012 +0100 +++ b/Lib/concurrent/futures/thread.py Mon Feb 27 15:00:14 2012 -0800 @@ -78,15 +78,19 @@ _base.LOGGER.critical('Exception in worker', exc_info=True) class ThreadPoolExecutor(_base.Executor): - def __init__(self, max_workers): + def __init__(self, max_workers, queue_size=0): """Initializes a new ThreadPoolExecutor instance. Args: max_workers: The maximum number of threads that can be used to execute the given calls. + queue_size: The maximum number of jobs that can be submitted to + this executor. Any job after this threshold will block the + executor until the queue is freed up. If non-positive number + is supplied, the queue is infinite. Default to 0. """ self._max_workers = max_workers - self._work_queue = queue.Queue() + self._work_queue = queue.Queue(queue_size) self._threads = set() self._shutdown = False self._shutdown_lock = threading.Lock()