MCPcopy Index your code
hub / github.com/python/cpython / _adjust_thread_count

Method _adjust_thread_count

Lib/concurrent/futures/thread.py:219–239  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

217 submit.__doc__ = _base.Executor.submit.__doc__
218
219 def _adjust_thread_count(self):
220 # if idle threads are available, don't spin new threads
221 if self._idle_semaphore.acquire(timeout=0):
222 return
223
224 # When the executor gets lost, the weakref callback will wake up
225 # the worker threads.
226 def weakref_cb(_, q=self._work_queue):
227 q.put(None)
228
229 num_threads = len(self._threads)
230 if num_threads < self._max_workers:
231 thread_name = '%s_%d' % (self._thread_name_prefix or self,
232 num_threads)
233 t = threading.Thread(name=thread_name, target=_worker,
234 args=(weakref.ref(self, weakref_cb),
235 self._create_worker_context(),
236 self._work_queue))
237 t.start()
238 self._threads.add(t)
239 _threads_queues[t] = self._work_queue
240
241 def _initializer_failed(self):
242 with self._shutdown_lock:

Callers 1

submitMethod · 0.95

Calls 3

startMethod · 0.95
acquireMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected