Skip to content

Commit 6104c59

Browse files
committed
change time calculations
1 parent 8dcf67c commit 6104c59

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

google/api_core/retry_streaming_async.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,9 @@
2929

3030
import asyncio
3131
import logging
32-
import datetime
32+
import time
3333

3434

35-
from google.api_core import datetime_helpers
3635
from google.api_core import exceptions
3736

3837
_LOGGER = logging.getLogger(__name__)
@@ -132,19 +131,19 @@ async def _handle_exception(self, exc) -> None:
132131
self.active_target = None
133132
await self._ensure_active_target()
134133

135-
def _subtract_time_from_budget(self, start_timestamp: datetime.datetime) -> None:
134+
def _subtract_time_from_budget(self, start_timestamp: float) -> None:
136135
"""
137136
Subtract the time elapsed since start_timestamp from the remaining
138137
timeout budget.
139138
140139
Args:
141-
- start_timestamp (datetime): The time at which the last operation
140+
- start_timestamp: The timestamp at which the last operation
142141
started.
143142
"""
144143
if self.remaining_timeout_budget is not None:
145144
self.remaining_timeout_budget -= (
146-
datetime_helpers.utcnow() - start_timestamp
147-
).total_seconds()
145+
time.monotonic() - start_timestamp
146+
)
148147

149148
async def _iteration_helper(self, iteration_routine: Awaitable) -> T:
150149
"""
@@ -168,7 +167,7 @@ async def _iteration_helper(self, iteration_routine: Awaitable) -> T:
168167
)
169168
try:
170169
# start the timer for the current operation
171-
start_timestamp = datetime_helpers.utcnow()
170+
start_timestamp = time.monotonic()
172171
# grab the next value from the active_target
173172
# Note: interrupting with asyncio.wait_for is expensive,
174173
# so we only check for timeouts at the start of each iteration

0 commit comments

Comments
 (0)