Skip to content

Commit 1e4f555

Browse files
author
=
committed
Update
1 parent abb84c8 commit 1e4f555

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

ThreadPoolExecutorPlus/thread.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,11 @@ def run(self):
130130
With another potential symptom is , depends on which task was last triggered by system, size of thread
131131
pool may not be precisely the same as expect just right after thread shrink happened.
132132
'''
133+
if self._thread_count_id < self._executor._min_workers:
134+
continue
135+
133136
with self._executor._free_thread_count_lock:
134-
if self._executor._free_thread_count > self._executor._min_workers and self._thread_count_id >= self._executor._min_workers:
137+
if self._executor._free_thread_count > self._executor._min_workers:
135138
self._executor._free_thread_count -= 1
136139
break
137140
else:
@@ -203,7 +206,7 @@ def __init__(self, max_workers=None, thread_name_prefix='',
203206
raise TypeError("initializer must be a callable")
204207

205208
self._max_workers = max_workers
206-
self._work_queue = queue.SimpleQueue()
209+
self._work_queue = queue.SimpleQueue(max_workers << 6)
207210
self._threads = _CustomWeakSet()
208211
self._broken = False
209212
self._shutdown = False
@@ -221,13 +224,12 @@ def set_daemon_opts(self , min_workers = None, max_workers = None, keep_alive_ti
221224
raise ValueError('min_workers is not allowed to set below 1')
222225
if max_workers is not None and max_workers < min_workers:
223226
raise ValueError('max_workers is not allowed to set below min_workers')
224-
with self._free_thread_count_lock:
225-
if min_workers is not None:
226-
self._min_workers = min_workers
227-
if max_workers is not None:
228-
self._max_workers = max_workers
229-
if keep_alive_time is not None:
230-
self._keep_alive_time = keep_alive_time
227+
if min_workers is not None:
228+
self._min_workers = min_workers
229+
if max_workers is not None:
230+
self._max_workers = max_workers
231+
if keep_alive_time is not None:
232+
self._keep_alive_time = keep_alive_time
231233

232234
def submit(self, fn, *args, **kwargs):
233235
with self._shutdown_lock:

0 commit comments

Comments
 (0)