concurrent: add private classes and exceptions (#3169)

This commit is contained in:
g.denis
2019-08-07 10:39:15 +02:00
committed by Sebastian Rittau
parent 29771aa1ee
commit 50f1988650
4 changed files with 138 additions and 18 deletions

View File

@@ -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: ...

View File

@@ -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: ...