mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-06-06 14:43:13 +03:00
Periodically send getState even without disconnect (341fb38
)
After some more tests, even if the server doesn't drop the connection, it might also just stop sending updates at all.
This commit is contained in:
parent
196275e9c8
commit
178643d3a1
|
@ -158,6 +158,14 @@ class TelegramBareClient:
|
||||||
self._last_ping = datetime.now()
|
self._last_ping = datetime.now()
|
||||||
self._ping_delay = timedelta(minutes=1)
|
self._ping_delay = timedelta(minutes=1)
|
||||||
|
|
||||||
|
# Also have another delay for GetStateRequest.
|
||||||
|
#
|
||||||
|
# If the connection is kept alive for long without invoking any
|
||||||
|
# high level request the server simply stops sending updates.
|
||||||
|
# TODO maybe we can have ._last_request instead if any req works?
|
||||||
|
self._last_state = datetime.now()
|
||||||
|
self._state_delay = timedelta(hours=1)
|
||||||
|
|
||||||
# Some errors are known but there's nothing we can do from the
|
# Some errors are known but there's nothing we can do from the
|
||||||
# background thread. If any of these happens, call .disconnect(),
|
# background thread. If any of these happens, call .disconnect(),
|
||||||
# and raise them next time .invoke() is tried to be called.
|
# and raise them next time .invoke() is tried to be called.
|
||||||
|
@ -579,6 +587,7 @@ class TelegramBareClient:
|
||||||
otherwise it should be called manually after enabling updates.
|
otherwise it should be called manually after enabling updates.
|
||||||
"""
|
"""
|
||||||
self.updates.process(self(GetStateRequest()))
|
self.updates.process(self(GetStateRequest()))
|
||||||
|
self._last_state = datetime.now()
|
||||||
|
|
||||||
def add_update_handler(self, handler):
|
def add_update_handler(self, handler):
|
||||||
"""Adds an update handler (a function which takes a TLObject,
|
"""Adds an update handler (a function which takes a TLObject,
|
||||||
|
@ -650,6 +659,10 @@ class TelegramBareClient:
|
||||||
))
|
))
|
||||||
self._last_ping = datetime.now()
|
self._last_ping = datetime.now()
|
||||||
|
|
||||||
|
if datetime.now() > self._last_state + self._state_delay:
|
||||||
|
self._sender.send(GetStateRequest())
|
||||||
|
self._last_state = datetime.now()
|
||||||
|
|
||||||
__log__.debug('Receiving items from the network...')
|
__log__.debug('Receiving items from the network...')
|
||||||
self._sender.receive(update_state=self.updates)
|
self._sender.receive(update_state=self.updates)
|
||||||
except TimeoutError:
|
except TimeoutError:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user