29
29
30
30
import asyncio
31
31
import logging
32
- import datetime
32
+ import time
33
33
34
34
35
- from google .api_core import datetime_helpers
36
35
from google .api_core import exceptions
37
36
38
37
_LOGGER = logging .getLogger (__name__ )
@@ -132,19 +131,19 @@ async def _handle_exception(self, exc) -> None:
132
131
self .active_target = None
133
132
await self ._ensure_active_target ()
134
133
135
- def _subtract_time_from_budget (self , start_timestamp : datetime . datetime ) -> None :
134
+ def _subtract_time_from_budget (self , start_timestamp : float ) -> None :
136
135
"""
137
136
Subtract the time elapsed since start_timestamp from the remaining
138
137
timeout budget.
139
138
140
139
Args:
141
- - start_timestamp (datetime) : The time at which the last operation
140
+ - start_timestamp: The timestamp at which the last operation
142
141
started.
143
142
"""
144
143
if self .remaining_timeout_budget is not None :
145
144
self .remaining_timeout_budget -= (
146
- datetime_helpers . utcnow () - start_timestamp
147
- ). total_seconds ()
145
+ time . monotonic () - start_timestamp
146
+ )
148
147
149
148
async def _iteration_helper (self , iteration_routine : Awaitable ) -> T :
150
149
"""
@@ -168,7 +167,7 @@ async def _iteration_helper(self, iteration_routine: Awaitable) -> T:
168
167
)
169
168
try :
170
169
# start the timer for the current operation
171
- start_timestamp = datetime_helpers . utcnow ()
170
+ start_timestamp = time . monotonic ()
172
171
# grab the next value from the active_target
173
172
# Note: interrupting with asyncio.wait_for is expensive,
174
173
# so we only check for timeouts at the start of each iteration
0 commit comments