2
0
mirror of https://github.com/pyrogram/pyrogram synced 2025-08-27 04:18:04 +00:00

Don't try to indefinitely reconnect at Connection layer

This commit is contained in:
Dan 2018-05-25 12:37:03 +02:00
parent 00b983ccc3
commit 81d3d5956c

View File

@ -26,6 +26,8 @@ log = logging.getLogger(__name__)
class Connection:
MAX_RETRIES = 5
MODES = {
0: TCPFull,
1: TCPAbridged,
@ -40,7 +42,7 @@ class Connection:
self.connection = None
def connect(self):
while True:
for i in range(Connection.MAX_RETRIES):
self.connection = self.mode(self.proxy)
try:
@ -51,6 +53,8 @@ class Connection:
time.sleep(1)
else:
break
else:
raise TimeoutError
def close(self):
self.connection.close()