Skip to content

Commit 2278dcf

Browse files
authored
Update thread.py
1 parent b5e86c4 commit 2278dcf

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

ThreadPoolExecutorPlus/thread.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,11 @@ 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+
232+
with self._free_thread_count_lock:
233+
_tflag = True if self._free_thread_count < self._min_workers else False
234+
235+
if _tflag and num_threads < self._max_workers:
232236
thread_name = '%s_%d' % (self._thread_name_prefix or self,
233237
num_threads)
234238
t = _CustomThread(name=thread_name,
@@ -272,4 +276,4 @@ def shutdown(self, wait=True):
272276
if wait:
273277
for t in self._threads:
274278
t.join()
275-
shutdown.__doc__ = _base.Executor.shutdown.__doc__
279+
shutdown.__doc__ = _base.Executor.shutdown.__doc__

0 commit comments

Comments
 (0)