2 from collections.abc import Generator, Iterable, Mapping, MutableMapping, MutableSequence
3 from multiprocessing.connection import Connection
4 from multiprocessing.context import BaseContext, Process
5 from multiprocessing.queues import Queue, SimpleQueue
6 from threading import Lock, Semaphore, Thread
7 from types import TracebackType
8 from typing import Any, Callable, Generic, Tuple, TypeVar
9 from weakref import ref
11 from ._base import Executor, Future
13 _threads_wakeups: MutableMapping[Any, Any]
14 _global_shutdown: bool
20 def __init__(self) -> None: ...
21 def close(self) -> None: ...
22 def wakeup(self) -> None: ...
23 def clear(self) -> None: ...
25 def _python_exit() -> None: ...
27 EXTRA_QUEUED_CALLS: int
29 _MAX_WINDOWS_WORKERS: int
31 class _RemoteTraceback(Exception):
33 def __init__(self, tb: TracebackType) -> None: ...
34 def __str__(self) -> str: ...
36 class _ExceptionWithTraceback:
39 def __init__(self, exc: BaseException, tb: TracebackType) -> None: ...
40 def __reduce__(self) -> str | Tuple[Any, ...]: ...
42 def _rebuild_exc(exc: Exception, tb: str) -> Exception: ...
46 class _WorkItem(Generic[_S]):
50 kwargs: Mapping[str, Any]
51 def __init__(self, future: Future[_S], fn: Callable[..., _S], args: Iterable[Any], kwargs: Mapping[str, Any]) -> None: ...
57 def __init__(self, work_id: int, exception: Exception | None = ..., result: Any | None = ...) -> None: ...
61 fn: Callable[..., Any]
63 kwargs: Mapping[str, Any]
64 def __init__(self, work_id: int, fn: Callable[..., Any], args: Iterable[Any], kwargs: Mapping[str, Any]) -> None: ...
66 if sys.version_info >= (3, 7):
67 class _SafeQueue(Queue[Future[Any]]):
68 pending_work_items: dict[int, _WorkItem[Any]]
70 thread_wakeup: _ThreadWakeup
71 if sys.version_info >= (3, 9):
74 max_size: int | None = ...,
77 pending_work_items: dict[int, _WorkItem[Any]],
79 thread_wakeup: _ThreadWakeup,
83 self, max_size: int | None = ..., *, ctx: BaseContext, pending_work_items: dict[int, _WorkItem[Any]]
85 def _on_queue_feeder_error(self, e: Exception, obj: _CallItem) -> None: ...
87 def _get_chunks(*iterables: Any, chunksize: int) -> Generator[Tuple[Any, ...], None, None]: ...
88 def _process_chunk(fn: Callable[..., Any], chunk: tuple[Any, None, None]) -> Generator[Any, None, None]: ...
90 result_queue: SimpleQueue[_WorkItem[Any]], work_id: int, result: Any | None = ..., exception: Exception | None = ...
93 if sys.version_info >= (3, 7):
95 call_queue: Queue[_CallItem],
96 result_queue: SimpleQueue[_ResultItem],
97 initializer: Callable[..., None] | None,
98 initargs: Tuple[Any, ...],
102 def _process_worker(call_queue: Queue[_CallItem], result_queue: SimpleQueue[_ResultItem]) -> None: ...
104 if sys.version_info >= (3, 9):
105 class _ExecutorManagerThread(Thread):
106 thread_wakeup: _ThreadWakeup
108 executor_reference: ref[Any]
109 processes: MutableMapping[int, Process]
110 call_queue: Queue[_CallItem]
111 result_queue: SimpleQueue[_ResultItem]
112 work_ids_queue: Queue[int]
113 pending_work_items: dict[int, _WorkItem[Any]]
114 def __init__(self, executor: ProcessPoolExecutor) -> None: ...
115 def run(self) -> None: ...
116 def add_call_item_to_queue(self) -> None: ...
117 def wait_result_broken_or_wakeup(self) -> tuple[Any, bool, str]: ...
118 def process_result_item(self, result_item: int | _ResultItem) -> None: ...
119 def is_shutting_down(self) -> bool: ...
120 def terminate_broken(self, cause: str) -> None: ...
121 def flag_executor_shutting_down(self) -> None: ...
122 def shutdown_workers(self) -> None: ...
123 def join_executor_internals(self) -> None: ...
124 def get_n_children_alive(self) -> int: ...
126 _system_limits_checked: bool
127 _system_limited: bool | None
129 def _check_system_limits() -> None: ...
130 def _chain_from_iterable_of_lists(iterable: Iterable[MutableSequence[Any]]) -> Any: ...
132 if sys.version_info >= (3, 7):
133 from ._base import BrokenExecutor
134 class BrokenProcessPool(BrokenExecutor): ...
137 class BrokenProcessPool(RuntimeError): ...
139 class ProcessPoolExecutor(Executor):
140 _mp_context: BaseContext | None = ...
141 _initializer: Callable[..., None] | None = ...
142 _initargs: Tuple[Any, ...] = ...
143 _executor_manager_thread: _ThreadWakeup
144 _processes: MutableMapping[int, Process]
145 _shutdown_thread: bool
147 _idle_worker_semaphore: Semaphore
150 _pending_work_items: dict[int, _WorkItem[Any]]
151 _cancel_pending_futures: bool
152 _executor_manager_thread_wakeup: _ThreadWakeup
153 _result_queue: SimpleQueue[Any]
154 _work_ids: Queue[Any]
155 if sys.version_info >= (3, 7):
158 max_workers: int | None = ...,
159 mp_context: BaseContext | None = ...,
160 initializer: Callable[..., None] | None = ...,
161 initargs: Tuple[Any, ...] = ...,
164 def __init__(self, max_workers: int | None = ...) -> None: ...
165 if sys.version_info >= (3, 9):
166 def _start_executor_manager_thread(self) -> None: ...
167 def _adjust_process_count(self) -> None: ...