classification
Title: concurrent.futures.ThreadPoolExecutor does not use a default value
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Claudiu.Popa, bquinlan, gvanrossum, josh.r, python-dev
Priority: normal Keywords: patch

Created on 2014-05-18 22:47 by Claudiu.Popa, last changed 2014-09-02 17:39 by python-dev. This issue is now closed.

Files
File name Uploaded Description Edit
concurrent_futures_workers.patch Claudiu.Popa, 2014-05-18 22:47 review
issue21527.patch Claudiu.Popa, 2014-08-28 08:56 Update max_workers review
Messages (5)
msg218763 - (view) Author: Claudiu Popa (Claudiu.Popa) * Date: 2014-05-18 22:47
As the title says, ThreadPoolExecutor does not use a default value for max_workers parameter, as ProcessPoolExecutor does. When the user does not care about the number of workers and wants only for something to run in background, he has to write code like this:

if processes:
   executor = ProcessPoolExecutor()
elif threads:
   executor = ThreadPoolExecutor(1) # or any other value

This situation can also occur when the class is passed as a factory function:

def create_pool(executor_factory):
   if executor_factory is process pool:
       executor = executor_factory()
   else:
       executor = executor_factory(1)

This patch proposes using the number of cores as the default value for max_workers.
For instance, multiprocessing.pool.ThreadPool uses the same value.
msg218840 - (view) Author: Josh Rosenberg (josh.r) * Date: 2014-05-20 10:29
+1. Makes it easier to swap Executors (which is a big selling point for the Executor framework), and number of cores is a reasonable default value.
msg226032 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2014-08-28 16:57
Looks good.
msg226212 - (view) Author: Claudiu Popa (Claudiu.Popa) * Date: 2014-09-01 06:45
Thank you, Guido.
msg226278 - (view) Author: Roundup Robot (python-dev) Date: 2014-09-02 17:39
New changeset 2805b0dca798 by Guido van Rossum in branch 'default':
Closes #21527: Add default number of workers to ThreadPoolExecutor. (Claudiu Popa.)
http://hg.python.org/cpython/rev/2805b0dca798
History
Date User Action Args
2014-09-02 17:39:27python-devsetstatus: open -> closed

nosy: + python-dev
messages: + msg226278

resolution: fixed
stage: commit review -> resolved
2014-09-01 06:45:04Claudiu.Popasetmessages: + msg226212
stage: patch review -> commit review
2014-08-28 16:57:38gvanrossumsetnosy: + gvanrossum
messages: + msg226032
2014-08-28 08:56:24Claudiu.Popasetfiles: + issue21527.patch
2014-06-22 05:49:55Claudiu.Popasetstage: patch review
2014-05-20 10:29:19josh.rsetnosy: + josh.r
messages: + msg218840
2014-05-18 22:47:47Claudiu.Popacreate