mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-02-17 03:51:05 +03:00
Add back the periodic PingRequest
This commit is contained in:
parent
a24b4020fe
commit
16a5ab3070
|
@ -13,6 +13,7 @@ from .errors import (
|
||||||
)
|
)
|
||||||
from .network import ConnectionMode
|
from .network import ConnectionMode
|
||||||
from .tl import Session, TLObject
|
from .tl import Session, TLObject
|
||||||
|
from .tl.functions import PingRequest
|
||||||
from .tl.functions.account import (
|
from .tl.functions.account import (
|
||||||
GetPasswordRequest
|
GetPasswordRequest
|
||||||
)
|
)
|
||||||
|
@ -136,6 +137,10 @@ class TelegramClient(TelegramBareClient):
|
||||||
# Constantly read for results and updates from within the main client
|
# Constantly read for results and updates from within the main client
|
||||||
self._recv_thread = None
|
self._recv_thread = None
|
||||||
|
|
||||||
|
# Default PingRequest delay
|
||||||
|
self._last_ping = datetime.now()
|
||||||
|
self._ping_delay = timedelta(minutes=1)
|
||||||
|
|
||||||
# endregion
|
# endregion
|
||||||
|
|
||||||
# region Connecting
|
# region Connecting
|
||||||
|
@ -950,6 +955,12 @@ class TelegramClient(TelegramBareClient):
|
||||||
def _recv_thread_impl(self):
|
def _recv_thread_impl(self):
|
||||||
while self._sender and self._sender.is_connected():
|
while self._sender and self._sender.is_connected():
|
||||||
try:
|
try:
|
||||||
|
if datetime.now() > self._last_ping + self._ping_delay:
|
||||||
|
self._sender.send(PingRequest(
|
||||||
|
int.from_bytes(os.urandom(8), 'big', signed=True)
|
||||||
|
))
|
||||||
|
self._last_ping = datetime.now()
|
||||||
|
|
||||||
self._sender.receive(update_state=self.updates)
|
self._sender.receive(update_state=self.updates)
|
||||||
except TimeoutError:
|
except TimeoutError:
|
||||||
# No problem.
|
# No problem.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user