mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-02-16 19:41:07 +03:00
Don't ignore more possible updates on .receive_updates() (closes #117)
This commit is contained in:
parent
c304ee903f
commit
2b85463ce6
|
@ -113,11 +113,13 @@ class MtProtoSender:
|
||||||
self._logger.info('Request result received')
|
self._logger.info('Request result received')
|
||||||
self._logger.debug('receive() released the lock')
|
self._logger.debug('receive() released the lock')
|
||||||
|
|
||||||
def receive_update(self, timeout=timedelta(seconds=5)):
|
def receive_updates(self, timeout=timedelta(seconds=5)):
|
||||||
"""Receives an update object and returns its result"""
|
"""Receives one or more update objects
|
||||||
|
and returns them as a list
|
||||||
|
"""
|
||||||
updates = []
|
updates = []
|
||||||
self.receive(timeout=timeout, updates=updates)
|
self.receive(timeout=timeout, updates=updates)
|
||||||
return updates[0]
|
return updates
|
||||||
|
|
||||||
def cancel_receive(self):
|
def cancel_receive(self):
|
||||||
"""Cancels any pending receive operation
|
"""Cancels any pending receive operation
|
||||||
|
|
|
@ -798,14 +798,20 @@ class TelegramClient(TelegramBareClient):
|
||||||
self._logger.debug('Updates thread acquired the lock')
|
self._logger.debug('Updates thread acquired the lock')
|
||||||
try:
|
try:
|
||||||
self._updates_thread_receiving.set()
|
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._updates_thread_receiving.clear()
|
||||||
self._logger.info('Received update from the updates thread')
|
self._logger.info(
|
||||||
for handler in self._update_handlers:
|
'Received {} update(s) from the updates thread'
|
||||||
handler(result)
|
.format(len(updates))
|
||||||
|
)
|
||||||
|
for update in updates:
|
||||||
|
for handler in self._update_handlers:
|
||||||
|
handler(update)
|
||||||
|
|
||||||
except ConnectionResetError:
|
except ConnectionResetError:
|
||||||
self._logger.info('Server disconnected us. Reconnecting...')
|
self._logger.info('Server disconnected us. Reconnecting...')
|
||||||
|
|
Loading…
Reference in New Issue
Block a user