Skip to content
This repository was archived by the owner on Feb 23, 2026. It is now read-only.
12 changes: 6 additions & 6 deletions google/api_core/future/polling.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,16 @@ def done(self, retry=DEFAULT_RETRY):
# pylint: disable=redundant-returns-doc, missing-raises-doc
raise NotImplementedError()

def _done_or_raise(self):
def _done_or_raise(self, retry=DEFAULT_RETRY):
"""Check if the future is done and raise if it's not."""
if not self.done():
if not self.done(retry):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be passed as a keyword argument

Suggested change
if not self.done(retry):
if not self.done(retry=retry):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On further thought, since this is a new kwarg, we don't want to force all clients that subclass it to add it in order to use the next google-api-core (this is a breaking change).

We should really only populate retry at all when explicitly passed a value for one.

Maybe something like this?

Suggested change
if not self.done(retry):
done_kwargs = {}
if retry is not DEFAULT_RETRY:
done_kwargs["retry"] = retry
if not self.done(**done_kwargs):

raise _OperationNotComplete()

def running(self):
"""True if the operation is currently running."""
return not self.done()

def _blocking_poll(self, timeout=None):
def _blocking_poll(self, timeout=None, retry=DEFAULT_RETRY):
"""Poll and wait for the Future to be resolved.

Args:
Expand All @@ -101,13 +101,13 @@ def _blocking_poll(self, timeout=None):
retry_ = self._retry.with_deadline(timeout)

try:
retry_(self._done_or_raise)()
retry_(self._done_or_raise)(retry)
Comment thread
IlyaFaer marked this conversation as resolved.
Outdated
except exceptions.RetryError:
raise concurrent.futures.TimeoutError(
"Operation did not complete within the designated " "timeout."
)

def result(self, timeout=None):
def result(self, timeout=None, retry=DEFAULT_RETRY):
"""Get the result of the operation, blocking if necessary.

Args:
Expand All @@ -122,7 +122,7 @@ def result(self, timeout=None):
google.api_core.GoogleAPICallError: If the operation errors or if
the timeout is reached before the operation completes.
"""
self._blocking_poll(timeout=timeout)
self._blocking_poll(timeout=timeout, retry=retry)
Comment thread
IlyaFaer marked this conversation as resolved.
Outdated

if self._exception is not None:
# pylint: disable=raising-bad-type
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/future/test_polling.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def __init__(self):
self.poll_count = 0
self.event = threading.Event()

def done(self):
def done(self, retry=polling.DEFAULT_RETRY):
self.poll_count += 1
self.event.wait()
self.set_result(42)
Expand All @@ -108,7 +108,7 @@ def test_result_with_polling():


class PollingFutureImplTimeout(PollingFutureImplWithPoll):
Comment thread
IlyaFaer marked this conversation as resolved.
def done(self):
def done(self, retry=polling.DEFAULT_RETRY):
time.sleep(1)
return False

Expand All @@ -130,7 +130,7 @@ def __init__(self, errors):
super(PollingFutureImplTransient, self).__init__()
self._errors = errors

def done(self):
def done(self, retry=polling.DEFAULT_RETRY):
if self._errors:
error, self._errors = self._errors[0], self._errors[1:]
raise error("testing")
Expand Down