Visitar URL original
bpo-29595: Expose max_queue_size in ThreadPoolExecutor by prayerslayer 路 Pull Request #143 路 python/cpython 路 GitHub
Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
expose max_queue_size in threadpoolexecutor
  • Loading branch information
prayerslayer committed Feb 17, 2017
commit 66c0031a08e6499486cc05db737ace0fb0a8de2d
4 changes: 2 additions & 2 deletions Lib/concurrent/futures/thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def _worker(executor_reference, work_queue):
_base.LOGGER.critical('Exception in worker', exc_info=True)

class ThreadPoolExecutor(_base.Executor):
def __init__(self, max_workers=None, thread_name_prefix=''):
def __init__(self, max_workers=None, thread_name_prefix='', max_queue_size=0):
"""Initializes a new ThreadPoolExecutor instance.

Args:
Expand All @@ -97,7 +97,7 @@ def __init__(self, max_workers=None, thread_name_prefix=''):
raise ValueError("max_workers must be greater than 0")

self._max_workers = max_workers
self._work_queue = queue.Queue()
self._work_queue = queue.Queue(maxsize=max_queue_size)
self._threads = set()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maxsize is the sole arg to the initializer of Queue so you could just supply max_queue_size since it's also pretty descriptive.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the sole arg to the initializer

What if this changes? Is it then still safe to just pass max_queue_size as positional argument?

self._shutdown = False
self._shutdown_lock = threading.Lock()
Expand Down