Skip to content

Commit 16843f6

Browse files
committed
Make multiprocessing.Queue a subclass of queue.Queue
Also change multiprocessing.Queue's put and get timeout arguments to allow None. This fixes a problem with logging.handlers.QueueHandler and QueueListener not accepting a multiprocessing.Queue as the queue argument. Declaring the Queue now needs to note what it will be used for. eg. q = multiprocessing.Queue() # type: multiprocessing.Queue[List[Any]]
1 parent b2df503 commit 16843f6

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

stdlib/3/multiprocessing/__init__.pyi

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
# Stubs for multiprocessing
22

3-
from typing import Any, Callable, Iterable, Mapping, Optional, Dict, List, Union
3+
from typing import Any, Callable, Iterable, Mapping, Optional, Dict, List, Union, TypeVar
44

55
from logging import Logger
66
from multiprocessing.context import BaseContext
77
from multiprocessing.managers import SyncManager
88
from multiprocessing.pool import AsyncResult
99
from multiprocessing.process import current_process as current_process
1010
import sys
11+
import queue
12+
13+
_T = TypeVar('_T')
1114

1215
class Lock():
1316
def acquire(self, block: bool = ..., timeout: int = ...) -> None: ...
@@ -93,15 +96,15 @@ class Process():
9396
def is_alive(self) -> bool: ...
9497
def join(self, timeout: Optional[float] = ...) -> None: ...
9598

96-
class Queue():
99+
class Queue(queue.Queue[_T]):
97100
def __init__(self, maxsize: int = ...) -> None: ...
98-
def get(self, block: bool = ..., timeout: float = ...) -> Any: ...
99-
def put(self, item: Any, block: bool = ..., timeout: float = ...) -> None: ...
101+
def get(self, block: bool = ..., timeout: Optional[float] = ...) -> _T: ...
102+
def put(self, item: _T, block: bool = ..., timeout: Optional[float] = ...) -> None: ...
100103
def qsize(self) -> int: ...
101104
def empty(self) -> bool: ...
102105
def full(self) -> bool: ...
103-
def put_nowait(self, item: Any) -> None: ...
104-
def get_nowait(self) -> Any: ...
106+
def put_nowait(self, item: _T) -> None: ...
107+
def get_nowait(self) -> _T: ...
105108
def close(self) -> None: ...
106109
def join_thread(self) -> None: ...
107110
def cancel_join_thread(self) -> None: ...

0 commit comments

Comments
 (0)