-
Notifications
You must be signed in to change notification settings - Fork 183
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
Fix/futures context #1512
Fix/futures context #1512
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
from __future__ import annotations | ||
|
||
import contextlib | ||
import warnings | ||
from abc import ABC | ||
from concurrent import futures | ||
from typing import Callable | ||
|
@@ -14,16 +14,27 @@ class FuturesExecutorMixin(ABC): | |
default=Factory(lambda: lambda: futures.ThreadPoolExecutor()), | ||
) | ||
|
||
futures_executor: futures.Executor = field( | ||
default=Factory(lambda self: self.create_futures_executor(), takes_self=True) | ||
_futures_executor: futures.Executor = field( | ||
default=Factory( | ||
lambda self: self.create_futures_executor(), | ||
takes_self=True, | ||
), | ||
alias="futures_executor", | ||
) | ||
|
||
def __del__(self) -> None: | ||
executor = self.futures_executor | ||
|
||
if executor is not None: | ||
self.futures_executor = None # pyright: ignore[reportAttributeAccessIssue] In practice this is safe, nobody will access this attribute after this point | ||
|
||
with contextlib.suppress(Exception): | ||
# don't raise exceptions in __del__ | ||
executor.shutdown(wait=True) | ||
@property | ||
def futures_executor(self) -> futures.Executor: | ||
self.__raise_deprecation_warning() | ||
return self._futures_executor | ||
|
||
@futures_executor.setter | ||
def futures_executor(self, value: futures.Executor) -> None: | ||
self.__raise_deprecation_warning() | ||
self._futures_executor = value | ||
|
||
def __raise_deprecation_warning(self) -> None: | ||
warnings.warn( | ||
"`FuturesExecutorMixin.futures_executor` is deprecated and will be removed in a future release. Use `FuturesExecutorMixin.create_futures_executor` instead.", | ||
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. maybe specify "use 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. Technically you could use it not as a context manager: executor = self.create_futures_executor()
executor.shutdown() |
||
DeprecationWarning, | ||
stacklevel=2, | ||
) |
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.
is this currently safe to remove without causing the issues that caused it to be added?
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.
I believe that was resolved by #1074. This particular method was only introduced as a clean-up effort.