Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions pinecone/grpc/future.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,17 @@ def _sync_state(self, grpc_future):
if self.done():
return

if grpc_future.cancelled():
if grpc_future.running() and not self.running():
if not self.set_running_or_notify_cancel():
grpc_future.cancel()
elif grpc_future.cancelled():
self.cancel()
elif grpc_future.exception(timeout=self._default_timeout):
self.set_exception(grpc_future.exception())
elif grpc_future.done():
try:
result = grpc_future.result(timeout=self._default_timeout)
self.set_result(result)
except Exception as e:
self.set_exception(e)
elif grpc_future.running():
self.set_running_or_notify_cancel()

def set_result(self, result):
if self._result_transformer:
Expand Down
4 changes: 4 additions & 0 deletions tests/unit_grpc/test_futures.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ def mock_grpc_future(
grpc_future.exception.return_value = exception
grpc_future.running.return_value = running
grpc_future.result.return_value = result
if exception:
grpc_future.result.side_effect = exception
return grpc_future


Expand Down Expand Up @@ -309,6 +311,7 @@ def test_result_catch_grpc_exceptions(self, mocker):
def test_exception_when_done_maps_grpc_exception(self, mocker):
grpc_future = mock_grpc_future(mocker, done=True)
grpc_future.exception.return_value = FakeGrpcError(mocker)
grpc_future.result.side_effect = grpc_future.exception.return_value

future = PineconeGrpcFuture(grpc_future)

Expand Down Expand Up @@ -467,6 +470,7 @@ def test_concurrent_futures_wait_first_exception(self, mocker):

grpc_future2 = mock_grpc_future(mocker, done=True)
grpc_future2.exception.return_value = Exception("Simulated gRPC error")
grpc_future2.result.side_effect = grpc_future2.exception.return_value
future2 = PineconeGrpcFuture(grpc_future2)

from concurrent.futures import wait, FIRST_EXCEPTION
Expand Down
Loading