Improve rate limiting and tests, for #80

This commit is contained in:
hugovk 2014-03-03 14:57:15 +02:00
parent a1867cc8d4
commit 40ea12a22f
2 changed files with 17 additions and 2 deletions

View file

@ -302,8 +302,10 @@ class _Network(object):
DELAY_TIME = 0.2
now = time.time()
if (now - self.last_call_time) < DELAY_TIME:
time.sleep(now - self.last_call_time - DELAY_TIME)
time_since_last = now - self.last_call_time
if time_since_last < DELAY_TIME:
time.sleep(DELAY_TIME - time_since_last)
self.last_call_time = now