summaryrefslogtreecommitdiff
path: root/Lib/concurrent
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2014-09-02 10:39:18 -0700
committerGuido van Rossum <guido@python.org>2014-09-02 10:39:18 -0700
commitcfd4661e78bd2256caaf80cf29588e5119e787b0 (patch)
tree507008e6f9977acff6a347cc085119c6a7917164 /Lib/concurrent
parent8257b6283e3ea41f5746835871dedcb00139bdfe (diff)
downloadcpython-git-cfd4661e78bd2256caaf80cf29588e5119e787b0.tar.gz
Closes #21527: Add default number of workers to ThreadPoolExecutor. (Claudiu Popa.)
Diffstat (limited to 'Lib/concurrent')
-rw-r--r--Lib/concurrent/futures/thread.py7
1 files changed, 6 insertions, 1 deletions
diff --git a/Lib/concurrent/futures/thread.py b/Lib/concurrent/futures/thread.py
index 8d6081cf15..3ae442d987 100644
--- a/Lib/concurrent/futures/thread.py
+++ b/Lib/concurrent/futures/thread.py
@@ -10,6 +10,7 @@ from concurrent.futures import _base
import queue
import threading
import weakref
+import os
# Workers are created as daemon threads. This is done to allow the interpreter
# to exit when there are still idle threads in a ThreadPoolExecutor's thread
@@ -80,13 +81,17 @@ def _worker(executor_reference, work_queue):
_base.LOGGER.critical('Exception in worker', exc_info=True)
class ThreadPoolExecutor(_base.Executor):
- def __init__(self, max_workers):
+ def __init__(self, max_workers=None):
"""Initializes a new ThreadPoolExecutor instance.
Args:
max_workers: The maximum number of threads that can be used to
execute the given calls.
"""
+ if max_workers is None:
+ # Use this number because ThreadPoolExecutor is often
+ # used to overlap I/O instead of CPU work.
+ max_workers = (os.cpu_count() or 1) * 5
if max_workers <= 0:
raise ValueError("max_workers must be greater than 0")