From 2b85463ce6438e07daf83c8febf685f9ffc3bb02 Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Fri, 16 Jun 2017 15:36:47 +0200 Subject: [PATCH] Don't ignore more possible updates on .receive_updates() (closes #117) --- telethon/network/mtproto_sender.py | 8 +++++--- telethon/telegram_client.py | 16 +++++++++++----- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/telethon/network/mtproto_sender.py b/telethon/network/mtproto_sender.py index d1ccca48..1301a863 100644 --- a/telethon/network/mtproto_sender.py +++ b/telethon/network/mtproto_sender.py @@ -113,11 +113,13 @@ class MtProtoSender: self._logger.info('Request result received') self._logger.debug('receive() released the lock') - def receive_update(self, timeout=timedelta(seconds=5)): - """Receives an update object and returns its result""" + def receive_updates(self, timeout=timedelta(seconds=5)): + """Receives one or more update objects + and returns them as a list + """ updates = [] self.receive(timeout=timeout, updates=updates) - return updates[0] + return updates def cancel_receive(self): """Cancels any pending receive operation diff --git a/telethon/telegram_client.py b/telethon/telegram_client.py index 0644d898..2f1b7252 100644 --- a/telethon/telegram_client.py +++ b/telethon/telegram_client.py @@ -798,14 +798,20 @@ class TelegramClient(TelegramBareClient): self._logger.debug('Updates thread acquired the lock') try: self._updates_thread_receiving.set() - self._logger.debug('Trying to receive updates from the updates thread') + self._logger.debug( + 'Trying to receive updates from the updates thread' + ) - result = self.sender.receive_update(timeout=timeout) + updates = self.sender.receive_updates(timeout=timeout) self._updates_thread_receiving.clear() - self._logger.info('Received update from the updates thread') - for handler in self._update_handlers: - handler(result) + self._logger.info( + 'Received {} update(s) from the updates thread' + .format(len(updates)) + ) + for update in updates: + for handler in self._update_handlers: + handler(update) except ConnectionResetError: self._logger.info('Server disconnected us. Reconnecting...')