mirror of
https://github.com/pyrogram/pyrogram
synced 2025-08-29 05:18:10 +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:
|
class Session:
|
||||||
INITIAL_SALT = 0x616e67656c696361
|
INITIAL_SALT = 0x616e67656c696361
|
||||||
NET_WORKERS = 1
|
NET_WORKERS = 1
|
||||||
|
START_TIMEOUT = 1
|
||||||
WAIT_TIMEOUT = 15
|
WAIT_TIMEOUT = 15
|
||||||
MAX_RETRIES = 5
|
MAX_RETRIES = 5
|
||||||
ACKS_THRESHOLD = 8
|
ACKS_THRESHOLD = 8
|
||||||
@ -130,8 +131,14 @@ class Session:
|
|||||||
Thread(target=self.recv, name="RecvThread").start()
|
Thread(target=self.recv, name="RecvThread").start()
|
||||||
|
|
||||||
self.current_salt = FutureSalt(0, 0, self.INITIAL_SALT)
|
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 = FutureSalt(
|
||||||
self.current_salt = self._send(functions.GetFutureSalts(1)).salts[0]
|
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 = Thread(target=self.next_salt, name="NextSaltThread")
|
||||||
self.next_salt_thread.start()
|
self.next_salt_thread.start()
|
||||||
@ -150,7 +157,8 @@ class Session:
|
|||||||
lang_pack="",
|
lang_pack="",
|
||||||
query=functions.help.GetConfig(),
|
query=functions.help.GetConfig(),
|
||||||
)
|
)
|
||||||
)
|
),
|
||||||
|
timeout=self.START_TIMEOUT
|
||||||
)
|
)
|
||||||
|
|
||||||
self.ping_thread = Thread(target=self.ping, name="PingThread")
|
self.ping_thread = Thread(target=self.ping, name="PingThread")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user