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

Method __init__

Lib/concurrent/futures/thread.py:161–197  ·  view source on GitHub ↗

Initializes a new ThreadPoolExecutor instance. Args: max_workers: The maximum number of threads that can be used to execute the given calls. thread_name_prefix: An optional name prefix to give our threads. initializer: A callable used to i

(self, max_workers=None, thread_name_prefix='',
                 initializer=None, initargs=(), **ctxkwargs)

Source from the content-addressed store, hash-verified

159 return WorkerContext.prepare(initializer, initargs)
160
161 def __init__(self, max_workers=None, thread_name_prefix='',
162 initializer=None, initargs=(), **ctxkwargs):
163 """Initializes a new ThreadPoolExecutor instance.
164
165 Args:
166 max_workers: The maximum number of threads that can be used to
167 execute the given calls.
168 thread_name_prefix: An optional name prefix to give our threads.
169 initializer: A callable used to initialize worker threads.
170 initargs: A tuple of arguments to pass to the initializer.
171 ctxkwargs: Additional arguments to cls.prepare_context().
172 """
173 if max_workers is None:
174 # ThreadPoolExecutor is often used to:
175 # * CPU bound task which releases GIL
176 # * I/O bound task (which releases GIL, of course)
177 #
178 # We use process_cpu_count + 4 for both types of tasks.
179 # But we limit it to 32 to avoid consuming surprisingly large resource
180 # on many core machine.
181 max_workers = min(32, (os.process_cpu_count() or 1) + 4)
182 if max_workers <= 0:
183 raise ValueError("max_workers must be greater than 0")
184
185 (self._create_worker_context,
186 self._resolve_work_item_task,
187 ) = type(self).prepare_context(initializer, initargs, **ctxkwargs)
188
189 self._max_workers = max_workers
190 self._work_queue = queue.SimpleQueue()
191 self._idle_semaphore = threading.Semaphore(0)
192 self._threads = set()
193 self._broken = False
194 self._shutdown = False
195 self._shutdown_lock = threading.Lock()
196 self._thread_name_prefix = (thread_name_prefix or
197 ("ThreadPoolExecutor-%d" % self._counter()))
198
199 def submit(self, fn, /, *args, **kwargs):
200 with self._shutdown_lock, _global_shutdown_lock:

Callers

nothing calls this directly

Calls 5

setFunction · 0.85
SimpleQueueMethod · 0.80
SemaphoreMethod · 0.80
LockMethod · 0.80
prepare_contextMethod · 0.45

Tested by

no test coverage detected