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

Method run

Lib/concurrent/futures/process.py:330–380  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

328 super().__init__()
329
330 def run(self):
331 # Main loop for the executor manager thread.
332
333 while True:
334 # gh-109047: During Python finalization, self.call_queue.put()
335 # creation of a thread can fail with RuntimeError.
336 try:
337 self.add_call_item_to_queue()
338 except BaseException as exc:
339 cause = format_exception(exc)
340 self.terminate_broken(cause)
341 return
342
343 result_item, is_broken, cause = self.wait_result_broken_or_wakeup()
344
345 if is_broken:
346 self.terminate_broken(cause)
347 return
348 if result_item is not None:
349 self.process_result_item(result_item)
350
351 process_exited = result_item.exit_pid is not None
352 if process_exited:
353 p = self.processes.pop(result_item.exit_pid)
354 p.join()
355
356 # Delete reference to result_item to avoid keeping references
357 # while waiting on new results.
358 del result_item
359
360 if executor := self.executor_reference():
361 if process_exited:
362 with self.shutdown_lock:
363 executor._adjust_process_count()
364 else:
365 executor._idle_worker_semaphore.release()
366 del executor
367
368 if self.is_shutting_down():
369 self.flag_executor_shutting_down()
370
371 # When only canceled futures remain in pending_work_items, our
372 # next call to wait_result_broken_or_wakeup would hang forever.
373 # This makes sure we have some running futures or none at all.
374 self.add_call_item_to_queue()
375
376 # Since no new work items can be added, it is safe to shutdown
377 # this thread if there are no pending work items.
378 if not self.pending_work_items:
379 self.join_executor_internals()
380 return
381
382 def add_call_item_to_queue(self):
383 # Fills call_queue with _WorkItems from pending_work_items.

Callers

nothing calls this directly

Calls 12

terminate_brokenMethod · 0.95
process_result_itemMethod · 0.95
is_shutting_downMethod · 0.95
format_exceptionFunction · 0.90
_adjust_process_countMethod · 0.80
popMethod · 0.45
joinMethod · 0.45
releaseMethod · 0.45

Tested by

no test coverage detected