From e42599051c3d1e593cfe5afa2068e899889ae645 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 3 Mar 2019 16:50:25 +0100 Subject: [PATCH] Use a lower timeout when starting a session to speed up re-connections Sometimes the server drops right after a successful connection and pyrogram keeps waiting up 15 seconds (current WAIT_TIMEOUT) for the first query to time out and start again a new connection. --- pyrogram/session/session.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/pyrogram/session/session.py b/pyrogram/session/session.py index 21bb1133..5392728f 100644 --- a/pyrogram/session/session.py +++ b/pyrogram/session/session.py @@ -48,6 +48,7 @@ class Result: class Session: INITIAL_SALT = 0x616e67656c696361 NET_WORKERS = 1 + START_TIMEOUT = 1 WAIT_TIMEOUT = 15 MAX_RETRIES = 5 ACKS_THRESHOLD = 8 @@ -130,8 +131,14 @@ class Session: Thread(target=self.recv, name="RecvThread").start() self.current_salt = FutureSalt(0, 0, self.INITIAL_SALT) - self.current_salt = FutureSalt(0, 0, self._send(functions.Ping(0)).new_server_salt) - self.current_salt = self._send(functions.GetFutureSalts(1)).salts[0] + self.current_salt = FutureSalt( + 0, 0, + self._send( + functions.Ping(0), + timeout=self.START_TIMEOUT + ).new_server_salt + ) + self.current_salt = self._send(functions.GetFutureSalts(1), timeout=self.START_TIMEOUT).salts[0] self.next_salt_thread = Thread(target=self.next_salt, name="NextSaltThread") self.next_salt_thread.start() @@ -150,7 +157,8 @@ class Session: lang_pack="", query=functions.help.GetConfig(), ) - ) + ), + timeout=self.START_TIMEOUT ) self.ping_thread = Thread(target=self.ping, name="PingThread")