mirror of
https://github.com/pyrogram/pyrogram
synced 2025-08-28 12:57:52 +00:00
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.
This commit is contained in:
parent
f84f9ec4df
commit
e42599051c
@ -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")
|
||||
|
Loading…
x
Reference in New Issue
Block a user