File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -118,6 +118,7 @@ def __init__(
118118 self ._credential_secret = credential_secret
119119 self ._version = version
120120 self ._last_query_time = time .time () - throttling
121+ self ._throttle_lock = asyncio .Lock ()
121122 self .tag = tag
122123 self .throttling = float (throttling )
123124
@@ -427,11 +428,16 @@ async def get_browse_nodes(
427428 return self ._deserialize_browse_nodes (browse_nodes_result ["browseNodes" ])
428429
429430 async def _throttle (self ) -> None :
430- """Wait for the throttling interval to elapse since the last API call."""
431- wait_time = self .throttling - (time .time () - self ._last_query_time )
432- if wait_time > 0 :
433- await asyncio .sleep (wait_time )
434- self ._last_query_time = time .time ()
431+ """Wait for the throttling interval to elapse since the last API call.
432+
433+ Uses asyncio.Lock to prevent race conditions when multiple coroutines
434+ attempt to make concurrent requests.
435+ """
436+ async with self ._throttle_lock :
437+ wait_time = self .throttling - (time .time () - self ._last_query_time )
438+ if wait_time > 0 :
439+ await asyncio .sleep (wait_time )
440+ self ._last_query_time = time .time ()
435441
436442 async def _make_request (
437443 self ,
You can’t perform that action at this time.
0 commit comments