4 from collections.abc import Callable, Iterable, Sequence
5 from ctypes import _CData
6 from logging import Logger
7 from multiprocessing import queues, synchronize
8 from multiprocessing.pool import Pool as _Pool
9 from multiprocessing.process import BaseProcess
10 from multiprocessing.sharedctypes import SynchronizedArray, SynchronizedBase
11 from typing import Any, Type, TypeVar, Union, overload
12 from typing_extensions import Literal
14 _LockLike = Union[synchronize.Lock, synchronize.RLock]
15 _CT = TypeVar("_CT", bound=_CData)
17 class ProcessError(Exception): ...
18 class BufferTooShort(ProcessError): ...
19 class TimeoutError(ProcessError): ...
20 class AuthenticationError(ProcessError): ...
22 class BaseContext(object):
23 Process: Type[BaseProcess]
24 ProcessError: Type[Exception]
25 BufferTooShort: Type[Exception]
26 TimeoutError: Type[Exception]
27 AuthenticationError: Type[Exception]
29 # N.B. The methods below are applied at runtime to generate
30 # multiprocessing.*, so the signatures should be identical (modulo self).
32 def current_process() -> BaseProcess: ...
33 if sys.version_info >= (3, 8):
35 def parent_process() -> BaseProcess | None: ...
37 def active_children() -> list[BaseProcess]: ...
38 def cpu_count(self) -> int: ...
39 # TODO: change return to SyncManager once a stub exists in multiprocessing.managers
40 def Manager(self) -> Any: ...
41 # TODO: change return to Pipe once a stub exists in multiprocessing.connection
42 def Pipe(self, duplex: bool = ...) -> Any: ...
44 self, parties: int, action: Callable[..., Any] | None = ..., timeout: float | None = ...
45 ) -> synchronize.Barrier: ...
46 def BoundedSemaphore(self, value: int = ...) -> synchronize.BoundedSemaphore: ...
47 def Condition(self, lock: _LockLike | None = ...) -> synchronize.Condition: ...
48 def Event(self) -> synchronize.Event: ...
49 def Lock(self) -> synchronize.Lock: ...
50 def RLock(self) -> synchronize.RLock: ...
51 def Semaphore(self, value: int = ...) -> synchronize.Semaphore: ...
52 def Queue(self, maxsize: int = ...) -> queues.Queue[Any]: ...
53 def JoinableQueue(self, maxsize: int = ...) -> queues.JoinableQueue[Any]: ...
54 def SimpleQueue(self) -> queues.SimpleQueue[Any]: ...
57 processes: int | None = ...,
58 initializer: Callable[..., Any] | None = ...,
59 initargs: Iterable[Any] = ...,
60 maxtasksperchild: int | None = ...,
63 def RawValue(self, typecode_or_type: Type[_CT], *args: Any) -> _CT: ...
65 def RawValue(self, typecode_or_type: str, *args: Any) -> Any: ...
67 def RawArray(self, typecode_or_type: Type[_CT], size_or_initializer: int | Sequence[Any]) -> ctypes.Array[_CT]: ...
69 def RawArray(self, typecode_or_type: str, size_or_initializer: int | Sequence[Any]) -> Any: ...
71 def Value(self, typecode_or_type: Type[_CT], *args: Any, lock: Literal[False]) -> _CT: ...
73 def Value(self, typecode_or_type: Type[_CT], *args: Any, lock: Literal[True] | _LockLike) -> SynchronizedBase[_CT]: ...
75 def Value(self, typecode_or_type: str, *args: Any, lock: Literal[True] | _LockLike) -> SynchronizedBase[Any]: ...
77 def Value(self, typecode_or_type: str | Type[_CData], *args: Any, lock: bool | _LockLike = ...) -> Any: ...
79 def Array(self, typecode_or_type: Type[_CT], size_or_initializer: int | Sequence[Any], *, lock: Literal[False]) -> _CT: ...
82 self, typecode_or_type: Type[_CT], size_or_initializer: int | Sequence[Any], *, lock: Literal[True] | _LockLike
83 ) -> SynchronizedArray[_CT]: ...
86 self, typecode_or_type: str, size_or_initializer: int | Sequence[Any], *, lock: Literal[True] | _LockLike
87 ) -> SynchronizedArray[Any]: ...
90 self, typecode_or_type: str | Type[_CData], size_or_initializer: int | Sequence[Any], *, lock: bool | _LockLike = ...
92 def freeze_support(self) -> None: ...
93 def get_logger(self) -> Logger: ...
94 def log_to_stderr(self, level: str | None = ...) -> Logger: ...
95 def allow_connection_pickling(self) -> None: ...
96 def set_executable(self, executable: str) -> None: ...
97 def set_forkserver_preload(self, module_names: list[str]) -> None: ...
98 if sys.platform != "win32":
100 def get_context(self, method: None = ...) -> DefaultContext: ...
102 def get_context(self, method: Literal["spawn"]) -> SpawnContext: ...
104 def get_context(self, method: Literal["fork"]) -> ForkContext: ...
106 def get_context(self, method: Literal["forkserver"]) -> ForkServerContext: ...
108 def get_context(self, method: str) -> BaseContext: ...
111 def get_context(self, method: None = ...) -> DefaultContext: ...
113 def get_context(self, method: Literal["spawn"]) -> SpawnContext: ...
115 def get_context(self, method: str) -> BaseContext: ...
116 def get_start_method(self, allow_none: bool = ...) -> str: ...
117 def set_start_method(self, method: str | None, force: bool = ...) -> None: ...
119 def reducer(self) -> str: ...
121 def reducer(self, reduction: str) -> None: ...
122 def _check_available(self) -> None: ...
124 class Process(BaseProcess):
125 _start_method: str | None
127 def _Popen(process_obj: BaseProcess) -> DefaultContext: ...
129 class DefaultContext(BaseContext):
130 Process: Type[multiprocessing.Process]
131 def __init__(self, context: BaseContext) -> None: ...
132 def set_start_method(self, method: str | None, force: bool = ...) -> None: ...
133 def get_start_method(self, allow_none: bool = ...) -> str: ...
134 def get_all_start_methods(self) -> list[str]: ...
136 _default_context: DefaultContext
138 if sys.platform != "win32":
139 class ForkProcess(BaseProcess):
142 def _Popen(process_obj: BaseProcess) -> Any: ...
143 class SpawnProcess(BaseProcess):
146 def _Popen(process_obj: BaseProcess) -> SpawnProcess: ...
147 class ForkServerProcess(BaseProcess):
150 def _Popen(process_obj: BaseProcess) -> Any: ...
151 class ForkContext(BaseContext):
153 Process: Type[ForkProcess]
154 class SpawnContext(BaseContext):
156 Process: Type[SpawnProcess]
157 class ForkServerContext(BaseContext):
159 Process: Type[ForkServerProcess]
162 class SpawnProcess(BaseProcess):
165 def _Popen(process_obj: BaseProcess) -> Any: ...
166 class SpawnContext(BaseContext):
168 Process: Type[SpawnProcess]
170 def _force_start_method(method: str) -> None: ...
171 def get_spawning_popen() -> Any | None: ...
172 def set_spawning_popen(popen: Any) -> None: ...
173 def assert_spawning(obj: Any) -> None: ...