From cf2c82d7bd53022faef766446a6200bd1829f47c Mon Sep 17 00:00:00 2001 From: Harmon Date: Wed, 6 Jan 2021 13:59:46 -0600 Subject: [PATCH] Improve clarity of rate limit handling in APIMethod.execute Also improve comment capitalization consistency and remove unnecessary comments --- tweepy/binder.py | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/tweepy/binder.py b/tweepy/binder.py index cd406e7..cfa437f 100644 --- a/tweepy/binder.py +++ b/tweepy/binder.py @@ -149,24 +149,15 @@ def bind_api(**config): # or maximum number of retries is reached. retries_performed = 0 while retries_performed < self.retry_count + 1: - # handle running out of api calls - if self.wait_on_rate_limit: - if self._reset_time is not None: - if self._remaining_calls is not None: - if self._remaining_calls < 1: - sleep_time = self._reset_time - int(time.time()) - if sleep_time > 0: - if self.wait_on_rate_limit_notify: - log.warning("Rate limit reached. Sleeping for: %d" % sleep_time) - time.sleep(sleep_time + 5) # sleep for few extra sec - - # if self.wait_on_rate_limit and self._reset_time is not None and \ - # self._remaining_calls is not None and self._remaining_calls < 1: - # sleep_time = self._reset_time - int(time.time()) - # if sleep_time > 0: - # if self.wait_on_rate_limit_notify: - # log.warning("Rate limit reached. Sleeping for: %d" % sleep_time) - # time.sleep(sleep_time + 5) # sleep for few extra sec + if (self.wait_on_rate_limit and self._reset_time is not None + and self._remaining_calls is not None + and self._remaining_calls < 1): + # Handle running out of API calls + sleep_time = self._reset_time - int(time.time()) + if sleep_time > 0: + if self.wait_on_rate_limit_notify: + log.warning("Rate limit reached. Sleeping for: %d" % sleep_time) + time.sleep(sleep_time + 5) # Sleep for few extra sec # Apply authentication auth = None -- 2.25.1