2 from _typeshed import Self
3 from contextlib import AbstractContextManager
4 from typing import Any, Callable, Generic, Iterable, Iterator, List, Mapping, TypeVar
6 if sys.version_info >= (3, 9):
7 from types import GenericAlias
9 _PT = TypeVar("_PT", bound=Pool)
13 class ApplyResult(Generic[_T]):
14 if sys.version_info >= (3, 8):
16 self, pool: Pool, callback: Callable[[_T], None] | None, error_callback: Callable[[BaseException], None] | None
21 cache: dict[int, ApplyResult[Any]],
22 callback: Callable[[_T], None] | None,
23 error_callback: Callable[[BaseException], None] | None,
25 def get(self, timeout: float | None = ...) -> _T: ...
26 def wait(self, timeout: float | None = ...) -> None: ...
27 def ready(self) -> bool: ...
28 def successful(self) -> bool: ...
29 if sys.version_info >= (3, 9):
30 def __class_getitem__(cls, item: Any) -> GenericAlias: ...
32 # alias created during issue #17805
33 AsyncResult = ApplyResult
35 class MapResult(ApplyResult[List[_T]]):
36 if sys.version_info >= (3, 8):
42 callback: Callable[[list[_T]], None] | None,
43 error_callback: Callable[[BaseException], None] | None,
48 cache: dict[int, ApplyResult[Any]],
51 callback: Callable[[list[_T]], None] | None,
52 error_callback: Callable[[BaseException], None] | None,
55 class IMapIterator(Iterator[_T]):
56 if sys.version_info >= (3, 8):
57 def __init__(self, pool: Pool) -> None: ...
59 def __init__(self, cache: dict[int, IMapIterator[Any]]) -> None: ...
60 def __iter__(self: _S) -> _S: ...
61 def next(self, timeout: float | None = ...) -> _T: ...
62 def __next__(self, timeout: float | None = ...) -> _T: ...
64 class IMapUnorderedIterator(IMapIterator[_T]): ...
66 class Pool(AbstractContextManager[Pool]):
69 processes: int | None = ...,
70 initializer: Callable[..., None] | None = ...,
71 initargs: Iterable[Any] = ...,
72 maxtasksperchild: int | None = ...,
73 context: Any | None = ...,
75 def apply(self, func: Callable[..., _T], args: Iterable[Any] = ..., kwds: Mapping[str, Any] = ...) -> _T: ...
78 func: Callable[..., _T],
79 args: Iterable[Any] = ...,
80 kwds: Mapping[str, Any] = ...,
81 callback: Callable[[_T], None] | None = ...,
82 error_callback: Callable[[BaseException], None] | None = ...,
83 ) -> AsyncResult[_T]: ...
84 def map(self, func: Callable[[_S], _T], iterable: Iterable[_S], chunksize: int | None = ...) -> list[_T]: ...
87 func: Callable[[_S], _T],
88 iterable: Iterable[_S],
89 chunksize: int | None = ...,
90 callback: Callable[[_T], None] | None = ...,
91 error_callback: Callable[[BaseException], None] | None = ...,
92 ) -> MapResult[_T]: ...
93 def imap(self, func: Callable[[_S], _T], iterable: Iterable[_S], chunksize: int | None = ...) -> IMapIterator[_T]: ...
95 self, func: Callable[[_S], _T], iterable: Iterable[_S], chunksize: int | None = ...
96 ) -> IMapIterator[_T]: ...
97 def starmap(self, func: Callable[..., _T], iterable: Iterable[Iterable[Any]], chunksize: int | None = ...) -> list[_T]: ...
100 func: Callable[..., _T],
101 iterable: Iterable[Iterable[Any]],
102 chunksize: int | None = ...,
103 callback: Callable[[_T], None] | None = ...,
104 error_callback: Callable[[BaseException], None] | None = ...,
105 ) -> AsyncResult[list[_T]]: ...
106 def close(self) -> None: ...
107 def terminate(self) -> None: ...
108 def join(self) -> None: ...
109 def __enter__(self: Self) -> Self: ...
111 class ThreadPool(Pool, AbstractContextManager[ThreadPool]):
113 self, processes: int | None = ..., initializer: Callable[..., Any] | None = ..., initargs: Iterable[Any] = ...
117 if sys.version_info >= (3, 8):