Multiprocessing fixes (#687)

* Fix type declarations for multiprocessing.pool.ThreadPool

The existing incomplete type declarations were replaced by a copy of
multiprocessing.Pool's declarations, suitably modified.

Fixes #683.

* Change iterable type to Iterable[Iterable[Any]] in starmap

multiprocessing.Pool and multiprocessing.pool.ThreadPool have starmap
and related methods, where the iterable argument is expected to yield
iterables. The type declarations now reflect this.
This commit is contained in:
Ryan C. Thompson
2016-11-12 17:31:54 -08:00
committed by Guido van Rossum
parent 88350e7f47
commit f36d7a3cd3
2 changed files with 42 additions and 20 deletions

View File

@@ -49,11 +49,11 @@ class Pool():
chunksize: Optional[int] = None) -> Iterable[Any]: ...
def starmap(self,
func: Callable[..., Any],
iterable: Iterable[Any]=(),
iterable: Iterable[Iterable[Any]]=(),
chunksize: Optional[int] = None) -> List[Any]: ...
def starmap_async(self,
func: Callable[..., Any],
iterable: Iterable[Any] = (),
iterable: Iterable[Iterable[Any]] = (),
chunksize: Optional[int] = None,
callback: Callable[..., None] = None,
error_callback: Callable[[BaseException], None] = None) -> AsyncResult: ...

View File

@@ -2,7 +2,7 @@
# NOTE: These are incomplete!
from typing import Any, Callable, Iterable, List, Sequence
from typing import Any, Callable, Iterable, Mapping, Optional, Dict, List
class AsyncResult():
def get(self, timeout: float = -1) -> Any: ...
@@ -11,26 +11,48 @@ class AsyncResult():
def successful(self) -> bool: ...
class ThreadPool():
def __init__(self, processes: int = ...) -> None: ...
def apply_async(self, func: Callable[..., Any],
args: Sequence[Any]=(),
kwds: Dict[str, Any]={},
callback: Callable[..., None] = None) -> AsyncResult: ...
def apply(self, func: Callable[..., Any],
args: Sequence[Any]=(),
def __init__(self, processes: Optional[int] = None,
initializer: Optional[Callable[..., None]] = None,
initargs: Iterable[Any] = ()) -> None: ...
def apply(self,
func: Callable[..., Any],
args: Iterable[Any]=(),
kwds: Dict[str, Any]={}) -> Any: ...
def map(self, func: Callable[..., Any],
iterable: Iterable[Any]=()) -> List[Any]: ...
def apply_async(self,
func: Callable[..., Any],
args: Iterable[Any]=(),
kwds: Dict[str, Any]={},
callback: Callable[..., None] = None,
error_callback: Callable[[BaseException], None] = None) -> AsyncResult: ...
def map(self,
func: Callable[..., Any],
iterable: Iterable[Any]=(),
chunksize: Optional[int] = None) -> List[Any]: ...
def map_async(self, func: Callable[..., Any],
iterable: Iterable[Any] = (),
chunksize: int = -1,
callback: Callable[..., None] = None) -> AsyncResult: ...
def imap(self, func: Callable[..., Any],
iterable: Iterable[Any]=()) -> Iterable[Any]: ...
def imap_async(self, func: Callable[..., Any],
chunksize: int = -1,
iterable: Iterable[Any]=(),
callback: Callable[..., None] = None) -> AsyncResult: ...
chunksize: Optional[int] = None,
callback: Callable[..., None] = None,
error_callback: Callable[[BaseException], None] = None) -> AsyncResult: ...
def imap(self,
func: Callable[..., Any],
iterable: Iterable[Any]=(),
chunksize: Optional[int] = None) -> Iterable[Any]: ...
def imap_unordered(self,
func: Callable[..., Any],
iterable: Iterable[Any]=(),
chunksize: Optional[int] = None) -> Iterable[Any]: ...
def starmap(self,
func: Callable[..., Any],
iterable: Iterable[Iterable[Any]]=(),
chunksize: Optional[int] = None) -> List[Any]: ...
def starmap_async(self,
func: Callable[..., Any],
iterable: Iterable[Iterable[Any]] = (),
chunksize: Optional[int] = None,
callback: Callable[..., None] = None,
error_callback: Callable[[BaseException], None] = None) -> AsyncResult: ...
def close(self) -> None: ...
def terminate(self) -> None: ...
def join(self) -> None: ...
def __enter__(self) -> 'ThreadPool': ...
def __exit__(self, exc_type, exc_val, exc_tb) -> None: ...