Skip to content

Commit fbe8d76

Browse files
committed
use throttle_delay result for throttled() and can_send_more()
1 parent a866d99 commit fbe8d76

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

kafka/conn.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -856,9 +856,9 @@ def throttled(self):
856856
"""
857857
Return True if we are connected but currently throttled.
858858
"""
859-
if self.state is ConnectionStates.CONNECTED:
860-
return self._throttle_time is not None and self._throttle_time > time.time()
861-
return False
859+
if self.state is not ConnectionStates.CONNECTED:
860+
return False
861+
return self.throttle_delay() > 0
862862

863863
def throttle_delay(self):
864864
"""
@@ -1105,11 +1105,8 @@ def _maybe_throttle(self, response):
11051105

11061106
def can_send_more(self):
11071107
"""Check for throttling / quota violations and max in-flight-requests"""
1108-
if self._throttle_time is not None:
1109-
if self._throttle_time > time.time():
1110-
return False
1111-
# Reset throttle_time if needed
1112-
self._throttle_time = None
1108+
if self.throttle_delay() > 0:
1109+
return False
11131110
max_ifrs = self.config['max_in_flight_requests_per_connection']
11141111
return len(self.in_flight_requests) < max_ifrs
11151112

0 commit comments

Comments
 (0)