massive update, probably broken
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-pyright / node_modules / pyright / dist / typeshed-fallback / stdlib / multiprocessing / context.pyi
1 import ctypes
2 import multiprocessing
3 import sys
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
13
14 _LockLike = Union[synchronize.Lock, synchronize.RLock]
15 _CT = TypeVar("_CT", bound=_CData)
16
17 class ProcessError(Exception): ...
18 class BufferTooShort(ProcessError): ...
19 class TimeoutError(ProcessError): ...
20 class AuthenticationError(ProcessError): ...
21
22 class BaseContext(object):
23     Process: Type[BaseProcess]
24     ProcessError: Type[Exception]
25     BufferTooShort: Type[Exception]
26     TimeoutError: Type[Exception]
27     AuthenticationError: Type[Exception]
28
29     # N.B. The methods below are applied at runtime to generate
30     # multiprocessing.*, so the signatures should be identical (modulo self).
31     @staticmethod
32     def current_process() -> BaseProcess: ...
33     if sys.version_info >= (3, 8):
34         @staticmethod
35         def parent_process() -> BaseProcess | None: ...
36     @staticmethod
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: ...
43     def Barrier(
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]: ...
55     def Pool(
56         self,
57         processes: int | None = ...,
58         initializer: Callable[..., Any] | None = ...,
59         initargs: Iterable[Any] = ...,
60         maxtasksperchild: int | None = ...,
61     ) -> _Pool: ...
62     @overload
63     def RawValue(self, typecode_or_type: Type[_CT], *args: Any) -> _CT: ...
64     @overload
65     def RawValue(self, typecode_or_type: str, *args: Any) -> Any: ...
66     @overload
67     def RawArray(self, typecode_or_type: Type[_CT], size_or_initializer: int | Sequence[Any]) -> ctypes.Array[_CT]: ...
68     @overload
69     def RawArray(self, typecode_or_type: str, size_or_initializer: int | Sequence[Any]) -> Any: ...
70     @overload
71     def Value(self, typecode_or_type: Type[_CT], *args: Any, lock: Literal[False]) -> _CT: ...
72     @overload
73     def Value(self, typecode_or_type: Type[_CT], *args: Any, lock: Literal[True] | _LockLike) -> SynchronizedBase[_CT]: ...
74     @overload
75     def Value(self, typecode_or_type: str, *args: Any, lock: Literal[True] | _LockLike) -> SynchronizedBase[Any]: ...
76     @overload
77     def Value(self, typecode_or_type: str | Type[_CData], *args: Any, lock: bool | _LockLike = ...) -> Any: ...
78     @overload
79     def Array(self, typecode_or_type: Type[_CT], size_or_initializer: int | Sequence[Any], *, lock: Literal[False]) -> _CT: ...
80     @overload
81     def Array(
82         self, typecode_or_type: Type[_CT], size_or_initializer: int | Sequence[Any], *, lock: Literal[True] | _LockLike
83     ) -> SynchronizedArray[_CT]: ...
84     @overload
85     def Array(
86         self, typecode_or_type: str, size_or_initializer: int | Sequence[Any], *, lock: Literal[True] | _LockLike
87     ) -> SynchronizedArray[Any]: ...
88     @overload
89     def Array(
90         self, typecode_or_type: str | Type[_CData], size_or_initializer: int | Sequence[Any], *, lock: bool | _LockLike = ...
91     ) -> Any: ...
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":
99         @overload
100         def get_context(self, method: None = ...) -> DefaultContext: ...
101         @overload
102         def get_context(self, method: Literal["spawn"]) -> SpawnContext: ...
103         @overload
104         def get_context(self, method: Literal["fork"]) -> ForkContext: ...
105         @overload
106         def get_context(self, method: Literal["forkserver"]) -> ForkServerContext: ...
107         @overload
108         def get_context(self, method: str) -> BaseContext: ...
109     else:
110         @overload
111         def get_context(self, method: None = ...) -> DefaultContext: ...
112         @overload
113         def get_context(self, method: Literal["spawn"]) -> SpawnContext: ...
114         @overload
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: ...
118     @property
119     def reducer(self) -> str: ...
120     @reducer.setter
121     def reducer(self, reduction: str) -> None: ...
122     def _check_available(self) -> None: ...
123
124 class Process(BaseProcess):
125     _start_method: str | None
126     @staticmethod
127     def _Popen(process_obj: BaseProcess) -> DefaultContext: ...
128
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]: ...
135
136 _default_context: DefaultContext
137
138 if sys.platform != "win32":
139     class ForkProcess(BaseProcess):
140         _start_method: str
141         @staticmethod
142         def _Popen(process_obj: BaseProcess) -> Any: ...
143     class SpawnProcess(BaseProcess):
144         _start_method: str
145         @staticmethod
146         def _Popen(process_obj: BaseProcess) -> SpawnProcess: ...
147     class ForkServerProcess(BaseProcess):
148         _start_method: str
149         @staticmethod
150         def _Popen(process_obj: BaseProcess) -> Any: ...
151     class ForkContext(BaseContext):
152         _name: str
153         Process: Type[ForkProcess]
154     class SpawnContext(BaseContext):
155         _name: str
156         Process: Type[SpawnProcess]
157     class ForkServerContext(BaseContext):
158         _name: str
159         Process: Type[ForkServerProcess]
160
161 else:
162     class SpawnProcess(BaseProcess):
163         _start_method: str
164         @staticmethod
165         def _Popen(process_obj: BaseProcess) -> Any: ...
166     class SpawnContext(BaseContext):
167         _name: str
168         Process: Type[SpawnProcess]
169
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: ...