Fix "Must wait error" not causing updates thread to sleep

This commit is contained in:
Lonami Exo 2017-04-11 09:58:22 +02:00
parent 6d1ce4d48d
commit 4fa43f231f

View File

@ -43,6 +43,9 @@ class MtProtoSender:
self.updates_thread_running = False self.updates_thread_running = False
self.updates_thread_receiving = False self.updates_thread_receiving = False
# Sleep amount on "must sleep" error for the updates thread to sleep too
self.updates_thread_sleep = None
self.updates_thread = Thread( self.updates_thread = Thread(
target=self.updates_thread_method, name='Updates thread') target=self.updates_thread_method, name='Updates thread')
@ -336,6 +339,8 @@ class MtProtoSender:
request.confirm_received = False request.confirm_received = False
if error.message.startswith('FLOOD_WAIT_'): if error.message.startswith('FLOOD_WAIT_'):
self.updates_thread_sleep = error.additional_data
print('Should wait {}s. Sleeping until then.'.format( print('Should wait {}s. Sleeping until then.'.format(
error.additional_data)) error.additional_data))
sleep(error.additional_data) sleep(error.additional_data)
@ -396,8 +401,12 @@ class MtProtoSender:
# since it's possible to early 'continue' the loop to reach # since it's possible to early 'continue' the loop to reach
# the next iteration, but we still should to sleep. # the next iteration, but we still should to sleep.
if self.updates_thread_running: if self.updates_thread_running:
# Longer sleep if we're not expecting any update (only pings) if self.updates_thread_sleep:
sleep(0.1 if self.on_update_handlers else 1) sleep(self.updates_thread_sleep)
self.updates_thread_sleep = None
else:
# Longer sleep if we're not expecting updates (only pings)
sleep(0.1 if self.on_update_handlers else 1)
# Only try to receive updates if we're not waiting to receive a request # Only try to receive updates if we're not waiting to receive a request
if not self.waiting_receive: if not self.waiting_receive: