Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit de7b51a

Browse files
committed
removed extra CancelledError handling
1 parent 14c195c commit de7b51a

File tree

2 files changed

+6
-19
lines changed

2 files changed

+6
-19
lines changed

google/api_core/retry_streaming_async.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,11 @@ async def _iteration_helper(self, iteration_routine: Awaitable) -> T:
170170
self._check_timeout(datetime_helpers.utcnow())
171171
try:
172172
# grab the next value from the active_target
173-
# Note: interrupting with asyncio.wait_for is expensive,
174-
# so we only check for timeouts at the start of each iteration
173+
# Note: here would be a good place to add a timeout, like asyncio.wait_for.
174+
# But wait_for is expensive, so we only check for timeouts at the
175+
# start of each iteration.
175176
return await iteration_routine
176-
except (Exception, asyncio.CancelledError) as exc:
177+
except Exception as exc:
177178
await self._handle_exception(exc)
178179
# if retryable exception was handled, find the next value to return
179180
return await self.__anext__()

tests/asyncio/test_retry_async.py

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -541,9 +541,9 @@ def increase_time(sleep_delay):
541541
assert total_wait == 7
542542

543543
@pytest.mark.asyncio
544-
async def test___call___generator_await_cancel_retryable(self):
544+
async def test___call___generator_cancellations(self):
545545
"""
546-
cancel calls should be supported as retryable errors
546+
cancel calls should propagate to the generator
547547
"""
548548
# test without cancel as retryable
549549
retry_ = retry_async.AsyncRetry(is_stream=True)
@@ -558,20 +558,6 @@ async def test___call___generator_await_cancel_retryable(self):
558558
await task
559559
with pytest.raises(StopAsyncIteration):
560560
await generator.__anext__()
561-
# test with cancel as retryable
562-
retry_cancel_ = retry_async.AsyncRetry(
563-
predicate=retry_async.if_exception_type(asyncio.CancelledError),
564-
is_stream=True,
565-
)
566-
generator = retry_cancel_(self._generator_mock)(sleep_time=0.2)
567-
await generator.__anext__() == 0
568-
await generator.__anext__() == 1
569-
task = asyncio.create_task(generator.__anext__())
570-
await asyncio.sleep(0.05)
571-
task.cancel()
572-
await task
573-
assert task.result() == 0
574-
await generator.__anext__() == 1
575561

576562
@mock.patch("asyncio.sleep", autospec=True)
577563
@pytest.mark.asyncio

0 commit comments

Comments
 (0)