-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added initial rework of the concurrent.futures module #5646
Merged
Merged
Changes from 6 commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
5285d39
Added initial rework of the concurrent.futures module
HunterAP23 3d8d8ab
Minor fixes
HunterAP23 69a5a03
Fixed some generics & changed to collections over typing for some types
HunterAP23 c408496
Switched thread to use queues instead of multiprocessing.queues
HunterAP23 cf486b1
More fixes
HunterAP23 e63acf4
More fixes following results from running tests locally
HunterAP23 8452717
Merge remote-tracking branch 'origin/master' into hunter
Akuli 49150a6
Tmp commit of changes
HunterAP23 bf01949
Merge branch 'master' of https://github.com/python/typeshed
HunterAP23 a7b8a87
Minor flake8 fix
HunterAP23 6c5b37b
Fixing some issues
HunterAP23 8fe6f7d
Fixed a weakref.ref issue
HunterAP23 cb7843b
Fixed one more weakref issue
HunterAP23 6c82496
Fixed some issues with required version
HunterAP23 bfdbc03
Fixed more python min version requirements
HunterAP23 c5ec620
More min version fixes
HunterAP23 4fb3b5c
Fixed misc error in workflow regarded outdated pip
HunterAP23 6dc70cc
Replaced any usage of Optional and Union with proper form as describe…
HunterAP23 261beda
Fixed issue with using Callable definition
HunterAP23 580cdf8
Fixed last seen issues as per review
HunterAP23 563b89b
Fixed some basic issues & more proper import calls
HunterAP23 50bbdbc
Merge branch 'master' of https://github.com/python/typeshed
HunterAP23 c7fec25
Update stdlib/concurrent/futures/process.pyi
HunterAP23 d83538c
Update stdlib/concurrent/futures/process.pyi
HunterAP23 26186c0
Minor fixes
HunterAP23 aa500af
Merge branch 'master' of https://github.com/HunterAP23/typeshed
HunterAP23 1db3c67
Merge branch 'master' of https://github.com/python/typeshed
HunterAP23 bc4139d
More minor fixes
HunterAP23 7bf4226
Fixed up some issues & cleaned up imports
HunterAP23 9bae25f
Removed usage of Union
HunterAP23 b350059
Changed wait method to use Set of Future to work with mypy-primer for…
HunterAP23 001c56e
Reverted change to wait method and DoneAndNotDoneFutures class
HunterAP23 d7020fe
Fixed DoneAndNotDoneFutures again
HunterAP23 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,119 @@ | ||
import multiprocessing as mp | ||
import multiprocessing.connection as mpconn | ||
import multiprocessing.context as mpcont | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just use |
||
import multiprocessing.queues as mpq | ||
import sys | ||
from typing import Any, Callable, Optional, Tuple | ||
import threading | ||
import weakref | ||
from collections.abc import Generator, Iterable, Mapping, MutableMapping, MutableSequence | ||
from concurrent.futures import _base | ||
from types import TracebackType | ||
from typing import Any, Callable, Optional, Tuple, Union | ||
|
||
from ._base import Executor | ||
_threads_wakeups: weakref.WeakKeyDictionary | ||
_global_shutdown: bool | ||
|
||
EXTRA_QUEUED_CALLS: Any | ||
class _ThreadWakeup: | ||
_closed: bool | ||
_reader: mpconn.Connection | ||
_writer: mpconn.Connection | ||
def __init__(self) -> None: ... | ||
def close(self) -> None: ... | ||
def wakeup(self) -> None: ... | ||
def clear(self) -> None: ... | ||
|
||
def _python_exit() -> None: ... | ||
|
||
EXTRA_QUEUED_CALLS: int | ||
|
||
_MAX_WINDOWS_WORKERS: int | ||
|
||
class _RemoteTraceback(Exception): | ||
tb: str | ||
def __init__(self, tb: TracebackType) -> None: ... | ||
def __str__(self) -> str: ... | ||
|
||
class _ExceptionWithTraceback: | ||
exc: BaseException | ||
tb: TracebackType | ||
def __init__(self, exc: BaseException, tb: TracebackType) -> None: ... | ||
def __reduce__(self) -> Union[str, Tuple[Any, ...]]: ... | ||
|
||
def _rebuild_exc(exc, tb) -> Exception: ... | ||
|
||
class _WorkItem(object): | ||
HunterAP23 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
future: _base.Future | ||
fn: Callable[..., Any] | ||
args: Iterable[Any] | ||
kwargs: Mapping[str, Any] | ||
def __init__(self, future: _base.Future, fn: Callable[..., Any], args: Iterable[Any], kwargs: Mapping[str, Any]) -> None: ... | ||
|
||
class _ResultItem(object): | ||
work_id: int | ||
exception: Exception | ||
result: Any | ||
def __init__(self, work_id: int, exception: Optional[Exception] = ..., result: Optional[Any] = ...) -> None: ... | ||
|
||
class _CallItem(object): | ||
work_id: int | ||
fn: Callable[..., Any] | ||
args: Iterable[Any] | ||
kwargs: Mapping[str, Any] | ||
def __init__(self, work_id: int, fn: Callable[..., Any], args: Iterable[Any], kwargs: Mapping[str, Any]) -> None: ... | ||
|
||
class _SafeQueue(mpq.Queue): | ||
pending_work_items: MutableMapping[int, _WorkItem] | ||
shutdown_lock: threading.Lock | ||
thread_wakeup: _ThreadWakeup | ||
def __init__( | ||
self, | ||
max_size: Optional[int] = ..., | ||
*, | ||
ctx: mpcont.BaseContext, | ||
pending_work_items: MutableMapping[int, _WorkItem], | ||
shutdown_lock: threading.Lock, | ||
thread_wakeup: _ThreadWakeup, | ||
) -> None: ... | ||
def _on_queue_feeder_error(self, e, obj) -> None: ... | ||
|
||
def _get_chunks(*iterables: Any, chunksize: int) -> Generator[Tuple[Any], None, None]: ... | ||
HunterAP23 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
def _process_chunk(fn: Callable[..., Any], chunk: Tuple[Any, None, None]) -> Generator[Any, None, None]: ... | ||
def _sendback_result( | ||
result_queue: mpq.SimpleQueue[_WorkItem], work_id: int, result: Optional[Any] = ..., exception: Optional[Exception] = ... | ||
) -> None: ... | ||
def _process_worker( | ||
call_queue: mpq.Queue[_CallItem], | ||
result_queue: mpq.SimpleQueue[_ResultItem], | ||
initializer: Optional[Callable[..., None]], | ||
initargs: Tuple[Any, ...], | ||
) -> None: ... | ||
|
||
class _ExecutorManagerThread(threading.Thread): | ||
thread_wakeup: _ThreadWakeup | ||
shutdown_lock: threading.Lock | ||
executor_reference: weakref.ref | ||
processes: MutableMapping[int, mpcont.Process] | ||
call_queue: mpq.Queue[_CallItem] | ||
result_queue: mpq.SimpleQueue[_ResultItem] | ||
work_ids_queue: mpq.Queue[int] | ||
pending_work_items: MutableMapping[int, _WorkItem] | ||
def __init__(self, executor: ProcessPoolExecutor) -> None: ... | ||
def run(self) -> None: ... | ||
def add_call_item_to_queue(self) -> None: ... | ||
def wait_result_broken_or_wakeup(self) -> tuple[Any, bool, str]: ... | ||
def process_result_item(self, result_item: Any) -> None: ... | ||
def is_shutting_down(self) -> bool: ... | ||
def terminate_broken(self, cause: str) -> None: ... | ||
def flag_executor_shutting_down(self) -> None: ... | ||
def shutdown_workers(self) -> None: ... | ||
def join_executor_internals(self) -> None: ... | ||
def get_n_children_alive(self) -> int: ... | ||
|
||
_system_limits_checked: bool | ||
_system_limited: Optional[bool] | ||
|
||
def _check_system_limits() -> None: ... | ||
def _chain_from_iterable_of_lists(iterable: Iterable[MutableSequence[Any]]) -> Any: ... | ||
|
||
if sys.version_info >= (3, 7): | ||
from ._base import BrokenExecutor | ||
|
@@ -12,17 +122,31 @@ if sys.version_info >= (3, 7): | |
else: | ||
class BrokenProcessPool(RuntimeError): ... | ||
|
||
if sys.version_info >= (3, 7): | ||
from multiprocessing.context import BaseContext | ||
class ProcessPoolExecutor(Executor): | ||
class ProcessPoolExecutor(_base.Executor): | ||
_mp_context: Optional[mpcont.BaseContext] | ||
_initializer: Optional[Callable[..., None]] = ... | ||
_initargs: Tuple[Any, ...] = ... | ||
_executor_manager_thread: _ThreadWakeup | ||
_processes: MutableMapping[int, mpcont.Process] | ||
_shutdown_thread: bool | ||
_shutdown_lock: threading.Lock | ||
_idle_worker_semaphore: threading.Semaphore | ||
_broken: bool | ||
_queue_count: int | ||
_pending_work_items: MutableMapping[int, _WorkItem] | ||
_cancel_pending_futures: bool | ||
_executor_manager_thread_wakeup: _ThreadWakeup | ||
_result_queue: mpq.SimpleQueue | ||
_work_ids: mpq.Queue | ||
if sys.version_info >= (3, 7): | ||
def __init__( | ||
self, | ||
max_workers: Optional[int] = ..., | ||
mp_context: Optional[BaseContext] = ..., | ||
mp_context: Optional[mpcont.BaseContext] = ..., | ||
initializer: Optional[Callable[..., None]] = ..., | ||
initargs: Tuple[Any, ...] = ..., | ||
) -> None: ... | ||
|
||
else: | ||
class ProcessPoolExecutor(Executor): | ||
else: | ||
def __init__(self, max_workers: Optional[int] = ...) -> None: ... | ||
def _start_executor_manager_thread(self) -> None: ... | ||
def _adjust_process_count(self) -> None: ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As these have concrete values (and are not supposed to be overwritten), we should use
List
andDict
, instead of the abstract classes.