Skip to content

Commit f36d7a3

Browse files
DarwinAwardWinnergvanrossum
authored andcommitted
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.
1 parent 88350e7 commit f36d7a3

File tree

2 files changed

+42
-20
lines changed

2 files changed

+42
-20
lines changed

stdlib/3/multiprocessing/__init__.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ class Pool():
4949
chunksize: Optional[int] = None) -> Iterable[Any]: ...
5050
def starmap(self,
5151
func: Callable[..., Any],
52-
iterable: Iterable[Any]=(),
52+
iterable: Iterable[Iterable[Any]]=(),
5353
chunksize: Optional[int] = None) -> List[Any]: ...
5454
def starmap_async(self,
5555
func: Callable[..., Any],
56-
iterable: Iterable[Any] = (),
56+
iterable: Iterable[Iterable[Any]] = (),
5757
chunksize: Optional[int] = None,
5858
callback: Callable[..., None] = None,
5959
error_callback: Callable[[BaseException], None] = None) -> AsyncResult: ...

stdlib/3/multiprocessing/pool.pyi

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# NOTE: These are incomplete!
44

5-
from typing import Any, Callable, Iterable, List, Sequence
5+
from typing import Any, Callable, Iterable, Mapping, Optional, Dict, List
66

77
class AsyncResult():
88
def get(self, timeout: float = -1) -> Any: ...
@@ -11,26 +11,48 @@ class AsyncResult():
1111
def successful(self) -> bool: ...
1212

1313
class ThreadPool():
14-
def __init__(self, processes: int = ...) -> None: ...
15-
def apply_async(self, func: Callable[..., Any],
16-
args: Sequence[Any]=(),
17-
kwds: Dict[str, Any]={},
18-
callback: Callable[..., None] = None) -> AsyncResult: ...
19-
def apply(self, func: Callable[..., Any],
20-
args: Sequence[Any]=(),
14+
def __init__(self, processes: Optional[int] = None,
15+
initializer: Optional[Callable[..., None]] = None,
16+
initargs: Iterable[Any] = ()) -> None: ...
17+
def apply(self,
18+
func: Callable[..., Any],
19+
args: Iterable[Any]=(),
2120
kwds: Dict[str, Any]={}) -> Any: ...
22-
def map(self, func: Callable[..., Any],
23-
iterable: Iterable[Any]=()) -> List[Any]: ...
21+
def apply_async(self,
22+
func: Callable[..., Any],
23+
args: Iterable[Any]=(),
24+
kwds: Dict[str, Any]={},
25+
callback: Callable[..., None] = None,
26+
error_callback: Callable[[BaseException], None] = None) -> AsyncResult: ...
27+
def map(self,
28+
func: Callable[..., Any],
29+
iterable: Iterable[Any]=(),
30+
chunksize: Optional[int] = None) -> List[Any]: ...
2431
def map_async(self, func: Callable[..., Any],
2532
iterable: Iterable[Any] = (),
26-
chunksize: int = -1,
27-
callback: Callable[..., None] = None) -> AsyncResult: ...
28-
def imap(self, func: Callable[..., Any],
29-
iterable: Iterable[Any]=()) -> Iterable[Any]: ...
30-
def imap_async(self, func: Callable[..., Any],
31-
chunksize: int = -1,
32-
iterable: Iterable[Any]=(),
33-
callback: Callable[..., None] = None) -> AsyncResult: ...
33+
chunksize: Optional[int] = None,
34+
callback: Callable[..., None] = None,
35+
error_callback: Callable[[BaseException], None] = None) -> AsyncResult: ...
36+
def imap(self,
37+
func: Callable[..., Any],
38+
iterable: Iterable[Any]=(),
39+
chunksize: Optional[int] = None) -> Iterable[Any]: ...
40+
def imap_unordered(self,
41+
func: Callable[..., Any],
42+
iterable: Iterable[Any]=(),
43+
chunksize: Optional[int] = None) -> Iterable[Any]: ...
44+
def starmap(self,
45+
func: Callable[..., Any],
46+
iterable: Iterable[Iterable[Any]]=(),
47+
chunksize: Optional[int] = None) -> List[Any]: ...
48+
def starmap_async(self,
49+
func: Callable[..., Any],
50+
iterable: Iterable[Iterable[Any]] = (),
51+
chunksize: Optional[int] = None,
52+
callback: Callable[..., None] = None,
53+
error_callback: Callable[[BaseException], None] = None) -> AsyncResult: ...
3454
def close(self) -> None: ...
3555
def terminate(self) -> None: ...
3656
def join(self) -> None: ...
57+
def __enter__(self) -> 'ThreadPool': ...
58+
def __exit__(self, exc_type, exc_val, exc_tb) -> None: ...

0 commit comments

Comments
 (0)