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

Method __init__

Lib/multiprocessing/pool.py:183–262  ·  view source on GitHub ↗
(self, processes=None, initializer=None, initargs=(),
                 maxtasksperchild=None, context=None)

Source from the content-addressed store, hash-verified

181 return ctx.Process(*args, **kwds)
182
183 def __init__(self, processes=None, initializer=None, initargs=(),
184 maxtasksperchild=None, context=None):
185 # Attributes initialized early to make sure that they exist in
186 # __del__() if __init__() raises an exception
187 self._pool = []
188 self._state = INIT
189
190 self._ctx = context or get_context()
191 self._setup_queues()
192 self._taskqueue = queue.SimpleQueue()
193 # The _change_notifier queue exist to wake up self._handle_workers()
194 # when the cache (self._cache) is empty or when there is a change in
195 # the _state variable of the thread that runs _handle_workers.
196 self._change_notifier = self._ctx.SimpleQueue()
197 self._cache = _PoolCache(notifier=self._change_notifier)
198 self._maxtasksperchild = maxtasksperchild
199 self._initializer = initializer
200 self._initargs = initargs
201
202 if processes is None:
203 processes = os.process_cpu_count() or 1
204 if processes < 1:
205 raise ValueError("Number of processes must be at least 1")
206 if maxtasksperchild is not None:
207 if not isinstance(maxtasksperchild, int) or maxtasksperchild <= 0:
208 raise ValueError("maxtasksperchild must be a positive int or None")
209
210 if initializer is not None and not callable(initializer):
211 raise TypeError('initializer must be a callable')
212
213 self._processes = processes
214 try:
215 self._repopulate_pool()
216 except Exception:
217 for p in self._pool:
218 if p.exitcode is None:
219 p.terminate()
220 for p in self._pool:
221 p.join()
222 raise
223
224 sentinels = self._get_sentinels()
225
226 self._worker_handler = threading.Thread(
227 target=Pool._handle_workers,
228 args=(self._cache, self._taskqueue, self._ctx, self.Process,
229 self._processes, self._pool, self._inqueue, self._outqueue,
230 self._initializer, self._initargs, self._maxtasksperchild,
231 self._wrap_exception, sentinels, self._change_notifier)
232 )
233 self._worker_handler.daemon = True
234 self._worker_handler._state = RUN
235 self._worker_handler.start()
236
237
238 self._task_handler = threading.Thread(
239 target=Pool._handle_tasks,
240 args=(self._taskqueue, self._quick_put, self._outqueue,

Callers 4

__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45

Calls 8

_setup_queuesMethod · 0.95
_repopulate_poolMethod · 0.95
_get_sentinelsMethod · 0.95
_PoolCacheClass · 0.85
SimpleQueueMethod · 0.80
terminateMethod · 0.45
joinMethod · 0.45
startMethod · 0.45

Tested by

no test coverage detected