@@ -164,12 +164,14 @@ def __init__(self, max_workers=None, thread_name_prefix='',
164164 initializer: An callable used to initialize worker threads.
165165 initargs: A tuple of arguments to pass to the initializer.
166166 """
167+ self ._min_workers = 4
168+ self ._keep_alive_time = 100
167169 if max_workers is None :
168170 # Use this number because ThreadPoolExecutor is often
169171 # used to overlap I/O instead of CPU work.
170172 max_workers = DEFAULT_MAXIMUM_WORKER_NUM
171- if max_workers <= 0 :
172- raise ValueError ("max_workers must be greater than 0 " )
173+ if max_workers <= self . _min_workers :
174+ raise ValueError (f "max_workers must be greater than min_workers = { self . _min_workers } " )
173175
174176 if initializer is not None and not callable (initializer ):
175177 raise TypeError ("initializer must be a callable" )
@@ -186,12 +188,10 @@ def __init__(self, max_workers=None, thread_name_prefix='',
186188 ("ThreadPoolExecutor-%d" % self ._counter ()))
187189 self ._initializer = initializer
188190 self ._initargs = initargs
189- self ._min_workers = 4
190- self ._keep_alive_time = 100
191191
192192 def set_daemon_opts (self , min_workers = None , max_workers = None , keep_alive_time = None ):
193- if min_workers is not None and min_workers < 1 :
194- raise ValueError ('min_workers is not allowed to set below 1 ' )
193+ if min_workers is not None and min_workers < 2 :
194+ raise ValueError ('min_workers is not allowed to set below 2 ' )
195195 if max_workers is not None and max_workers < min_workers :
196196 raise ValueError ('max_workers is not allowed to set below min_workers' )
197197 if min_workers is not None :
@@ -228,7 +228,7 @@ def weakref_cb(_, q=self._work_queue):
228228 # TODO(bquinlan): Should avoid creating new threads if there are more
229229 # idle threads than items in the work queue.
230230 num_threads = len (self ._threads )
231- if self ._free_thread_count <= self ._min_workers and num_threads < self ._max_workers :
231+ if self ._free_thread_count < self ._min_workers and num_threads < self ._max_workers :
232232 thread_name = '%s_%d' % (self ._thread_name_prefix or self ,
233233 num_threads )
234234 t = _CustomThread (name = thread_name ,
0 commit comments