diff --git a/stdlib/3/concurrent/futures/_base.pyi b/stdlib/3/concurrent/futures/_base.pyi index 13037d87f..fd0421093 100644 --- a/stdlib/3/concurrent/futures/_base.pyi +++ b/stdlib/3/concurrent/futures/_base.pyi @@ -1,21 +1,26 @@ -from typing import TypeVar, Generic, Any, Iterable, Iterator, Callable, Tuple, Optional, Set +import threading +from logging import Logger +from typing import TypeVar, Generic, Any, Iterable, Iterator, Callable, Tuple, Optional, Set, List from types import TracebackType import sys FIRST_COMPLETED: str FIRST_EXCEPTION: str ALL_COMPLETED: str -PENDING: Any -RUNNING: Any -CANCELLED: Any -CANCELLED_AND_NOTIFIED: Any -FINISHED: Any -LOGGER: Any +PENDING: str +RUNNING: str +CANCELLED: str +CANCELLED_AND_NOTIFIED: str +FINISHED: str +LOGGER: Logger class Error(Exception): ... class CancelledError(Error): ... class TimeoutError(Error): ... +if sys.version_info >= (3, 7): + class BrokenExecutor(RuntimeError): ... + _T = TypeVar('_T') class Future(Generic[_T]): @@ -54,3 +59,42 @@ def as_completed(fs: Iterable[Future[_T]], timeout: Optional[float] = ...) -> It def wait(fs: Iterable[Future[_T]], timeout: Optional[float] = ..., return_when: str = ...) -> Tuple[Set[Future[_T]], Set[Future[_T]]]: ... + +class _Waiter: + event: threading.Event + finished_futures: List[Future] + def __init__(self) -> None: ... + def add_result(self, future: Future) -> None: ... + def add_exception(self, future: Future) -> None: ... + def add_cancelled(self, future: Future) -> None: ... + + +class _AsCompletedWaiter(_Waiter): + lock: threading.Lock + def __init__(self) -> None: ... + def add_result(self, future: Future) -> None: ... + def add_exception(self, future: Future) -> None: ... + def add_cancelled(self, future: Future) -> None: ... + + +class _FirstCompletedWaiter(_Waiter): + def add_result(self, future: Future) -> None: ... + def add_exception(self, future: Future) -> None: ... + def add_cancelled(self, future: Future) -> None: ... + + +class _AllCompletedWaiter(_Waiter): + num_pending_calls: int + stop_on_exception: bool + lock: threading.Lock + def __init__(self, num_pending_calls: int, stop_on_exception: bool) -> None: ... + def add_result(self, future: Future) -> None: ... + def add_exception(self, future: Future) -> None: ... + def add_cancelled(self, future: Future) -> None: ... + + +class _AcquireFutures: + futures: Iterable[Future] + def __init__(self, futures: Iterable[Future]) -> None: ... + def __enter__(self) -> None: ... + def __exit__(self, *args: Any) -> None: ... diff --git a/stdlib/3/concurrent/futures/thread.pyi b/stdlib/3/concurrent/futures/thread.pyi index e2b236b8d..c4f895d7a 100644 --- a/stdlib/3/concurrent/futures/thread.pyi +++ b/stdlib/3/concurrent/futures/thread.pyi @@ -1,7 +1,13 @@ -from typing import Any, Callable, Optional, Tuple -from ._base import Executor +from typing import Any, Callable, Optional, Tuple, TypeVar, Generic +from ._base import Executor, Future import sys +if sys.version_info >= (3, 7): + from ._base import BrokenExecutor + class BrokenThreadPool(BrokenExecutor): ... + +_S = TypeVar('_S') + class ThreadPoolExecutor(Executor): if sys.version_info >= (3, 7): def __init__(self, max_workers: Optional[int] = ..., @@ -13,3 +19,13 @@ class ThreadPoolExecutor(Executor): thread_name_prefix: str = ...) -> None: ... else: def __init__(self, max_workers: Optional[int] = ...) -> None: ... + + +class _WorkItem(Generic[_S]): + future: Future + fn: Callable[[Future[_S]], Any] + args: Any + kwargs: Any + def __init__(self, future: Future, fn: Callable[[Future[_S]], Any], args: Any, + kwargs: Any) -> None: ... + def run(self) -> None: ... diff --git a/third_party/2/concurrent/futures/_base.pyi b/third_party/2/concurrent/futures/_base.pyi index 13037d87f..fd0421093 100644 --- a/third_party/2/concurrent/futures/_base.pyi +++ b/third_party/2/concurrent/futures/_base.pyi @@ -1,21 +1,26 @@ -from typing import TypeVar, Generic, Any, Iterable, Iterator, Callable, Tuple, Optional, Set +import threading +from logging import Logger +from typing import TypeVar, Generic, Any, Iterable, Iterator, Callable, Tuple, Optional, Set, List from types import TracebackType import sys FIRST_COMPLETED: str FIRST_EXCEPTION: str ALL_COMPLETED: str -PENDING: Any -RUNNING: Any -CANCELLED: Any -CANCELLED_AND_NOTIFIED: Any -FINISHED: Any -LOGGER: Any +PENDING: str +RUNNING: str +CANCELLED: str +CANCELLED_AND_NOTIFIED: str +FINISHED: str +LOGGER: Logger class Error(Exception): ... class CancelledError(Error): ... class TimeoutError(Error): ... +if sys.version_info >= (3, 7): + class BrokenExecutor(RuntimeError): ... + _T = TypeVar('_T') class Future(Generic[_T]): @@ -54,3 +59,42 @@ def as_completed(fs: Iterable[Future[_T]], timeout: Optional[float] = ...) -> It def wait(fs: Iterable[Future[_T]], timeout: Optional[float] = ..., return_when: str = ...) -> Tuple[Set[Future[_T]], Set[Future[_T]]]: ... + +class _Waiter: + event: threading.Event + finished_futures: List[Future] + def __init__(self) -> None: ... + def add_result(self, future: Future) -> None: ... + def add_exception(self, future: Future) -> None: ... + def add_cancelled(self, future: Future) -> None: ... + + +class _AsCompletedWaiter(_Waiter): + lock: threading.Lock + def __init__(self) -> None: ... + def add_result(self, future: Future) -> None: ... + def add_exception(self, future: Future) -> None: ... + def add_cancelled(self, future: Future) -> None: ... + + +class _FirstCompletedWaiter(_Waiter): + def add_result(self, future: Future) -> None: ... + def add_exception(self, future: Future) -> None: ... + def add_cancelled(self, future: Future) -> None: ... + + +class _AllCompletedWaiter(_Waiter): + num_pending_calls: int + stop_on_exception: bool + lock: threading.Lock + def __init__(self, num_pending_calls: int, stop_on_exception: bool) -> None: ... + def add_result(self, future: Future) -> None: ... + def add_exception(self, future: Future) -> None: ... + def add_cancelled(self, future: Future) -> None: ... + + +class _AcquireFutures: + futures: Iterable[Future] + def __init__(self, futures: Iterable[Future]) -> None: ... + def __enter__(self) -> None: ... + def __exit__(self, *args: Any) -> None: ... diff --git a/third_party/2/concurrent/futures/thread.pyi b/third_party/2/concurrent/futures/thread.pyi index e2b236b8d..c4f895d7a 100644 --- a/third_party/2/concurrent/futures/thread.pyi +++ b/third_party/2/concurrent/futures/thread.pyi @@ -1,7 +1,13 @@ -from typing import Any, Callable, Optional, Tuple -from ._base import Executor +from typing import Any, Callable, Optional, Tuple, TypeVar, Generic +from ._base import Executor, Future import sys +if sys.version_info >= (3, 7): + from ._base import BrokenExecutor + class BrokenThreadPool(BrokenExecutor): ... + +_S = TypeVar('_S') + class ThreadPoolExecutor(Executor): if sys.version_info >= (3, 7): def __init__(self, max_workers: Optional[int] = ..., @@ -13,3 +19,13 @@ class ThreadPoolExecutor(Executor): thread_name_prefix: str = ...) -> None: ... else: def __init__(self, max_workers: Optional[int] = ...) -> None: ... + + +class _WorkItem(Generic[_S]): + future: Future + fn: Callable[[Future[_S]], Any] + args: Any + kwargs: Any + def __init__(self, future: Future, fn: Callable[[Future[_S]], Any], args: Any, + kwargs: Any) -> None: ... + def run(self) -> None: ...