diff --git a/CHANGELOG.md b/CHANGELOG.md index cb0a4e021..968dfdead 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `BaseVectorStoreDriver.query_vector` for querying vector stores with vectors. +### Fixed + +- Occasional crash during `FuturesExecutorMixin` cleanup. + +### Deprecated + +- `FuturesExecutorMixin.futures_executor`. Use `FuturesExecutorMixin.create_futures_executor` instead. + ## [1.1.1] - 2025-01-03 ### Fixed diff --git a/griptape/mixins/futures_executor_mixin.py b/griptape/mixins/futures_executor_mixin.py index 142c38de5..3a36c265a 100644 --- a/griptape/mixins/futures_executor_mixin.py +++ b/griptape/mixins/futures_executor_mixin.py @@ -1,5 +1,6 @@ from __future__ import annotations +import warnings from abc import ABC from concurrent import futures from typing import Callable @@ -13,6 +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", ) + + @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.", + DeprecationWarning, + stacklevel=2, + ) diff --git a/tests/unit/mixins/test_futures_executor_mixin.py b/tests/unit/mixins/test_futures_executor_mixin.py index 437903fe3..0cc05eb61 100644 --- a/tests/unit/mixins/test_futures_executor_mixin.py +++ b/tests/unit/mixins/test_futures_executor_mixin.py @@ -1,5 +1,7 @@ from concurrent import futures +import pytest + from tests.mocks.mock_futures_executor import MockFuturesExecutor @@ -8,3 +10,9 @@ def test_futures_executor(self): executor = futures.ThreadPoolExecutor() assert MockFuturesExecutor(create_futures_executor=lambda: executor).futures_executor == executor + + def test_deprecated_futures_executor(self): + mock_executor = MockFuturesExecutor() + with pytest.warns(DeprecationWarning): + assert mock_executor.futures_executor + mock_executor.futures_executor = futures.ThreadPoolExecutor()