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

Function _process_worker

Lib/concurrent/futures/process.py:218–269  ·  view source on GitHub ↗

Evaluates calls from call_queue and places the results in result_queue. This worker is run in a separate process. Args: call_queue: A ctx.Queue of _CallItems that will be read and evaluated by the worker. result_queue: A ctx.Queue of _ResultItems that will writt

(call_queue, result_queue, initializer, initargs, max_tasks=None)

Source from the content-addressed store, hash-verified

216
217
218def _process_worker(call_queue, result_queue, initializer, initargs, max_tasks=None):
219 """Evaluates calls from call_queue and places the results in result_queue.
220
221 This worker is run in a separate process.
222
223 Args:
224 call_queue: A ctx.Queue of _CallItems that will be read and
225 evaluated by the worker.
226 result_queue: A ctx.Queue of _ResultItems that will written
227 to by the worker.
228 initializer: A callable initializer, or None
229 initargs: A tuple of args for the initializer
230 """
231 if initializer is not None:
232 try:
233 initializer(*initargs)
234 except BaseException:
235 _base.LOGGER.critical('Exception in initializer:', exc_info=True)
236 # The parent will notice that the process stopped and
237 # mark the pool broken
238 return
239 num_tasks = 0
240 exit_pid = None
241 while True:
242 call_item = call_queue.get(block=True)
243 if call_item is None:
244 # Wake up queue management thread
245 result_queue.put(os.getpid())
246 return
247
248 if max_tasks is not None:
249 num_tasks += 1
250 if num_tasks >= max_tasks:
251 exit_pid = os.getpid()
252
253 try:
254 r = call_item.fn(*call_item.args, **call_item.kwargs)
255 except BaseException as e:
256 exc = _ExceptionWithTraceback(e, e.__traceback__)
257 _sendback_result(result_queue, call_item.work_id, exception=exc,
258 exit_pid=exit_pid)
259 else:
260 _sendback_result(result_queue, call_item.work_id, result=r,
261 exit_pid=exit_pid)
262 del r
263
264 # Liberate the resource as soon as possible, to avoid holding onto
265 # open files or shared memory that is not needed anymore
266 del call_item
267
268 if exit_pid is not None:
269 return
270
271
272class _ExecutorManagerThread(threading.Thread):

Callers

nothing calls this directly

Calls 7

initializerFunction · 0.85
_sendback_resultFunction · 0.85
criticalMethod · 0.45
getMethod · 0.45
putMethod · 0.45
fnMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…