Skip to content

Commit

Permalink
Merge pull request #49 from Yoctol/handle-cancel
Browse files Browse the repository at this point in the history
fix: handle asyncio CancelledError separately so no retrying happens
  • Loading branch information
SoluMilken authored Dec 5, 2019
2 parents 892c22a + 1e3ca7a commit 197a0aa
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions serving_utils/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ async def async_predict(
try:
stub = self.get_round_robin_stub(is_async_stub=True)
response = await stub.Predict(request)
except asyncio.CancelledError:
raise
except EmptyPool:
self.logger.warning("serving_utils.Client -- empty pool")
self._setup_connections()
Expand Down
14 changes: 14 additions & 0 deletions serving_utils/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,20 @@ def server_fails_to_Predict_because_model_doesnt_exist(request):
assert exc_info.value.message == "Model XXX not found"


@pytest.mark.asyncio
async def test_asyncio_cancel_during_async_predict():
t = test_asyncio_cancel_during_async_predict
t.mock_gethostbyname_ex.return_value = ('localhost', [], ['1.2.3.4'])

mock_logger = mock.Mock()
c = Client(host='localhost', port=9999, n_trys=1, logger=mock_logger)
for stub in t.created_async_stubs:
stub.Predict.side_effect = aio.CancelledError()

with pytest.raises(aio.CancelledError):
await client_async_predict(c)


@pytest.mark.asyncio
async def test_model_not_found_error_passes_through_sync_predict():

Expand Down

0 comments on commit 197a0aa

Please sign in to comment.