2
0
mirror of https://github.com/pyrogram/pyrogram synced 2025-08-28 21:07:59 +00:00

Revert to fixed NET_WORKERS count

This commit is contained in:
Dan 2018-02-08 19:48:01 +01:00
parent 5885f38245
commit 7cee6b079f
2 changed files with 7 additions and 13 deletions

View File

@ -156,8 +156,7 @@ class Client:
self.test_mode, self.test_mode,
self.proxy, self.proxy,
self.auth_key, self.auth_key,
self.config.api_id, self.config.api_id
net_workers=self.workers
) )
terms = self.session.start() terms = self.session.start()
@ -262,8 +261,7 @@ class Client:
self.test_mode, self.test_mode,
self.proxy, self.proxy,
self.auth_key, self.auth_key,
self.config.api_id, self.config.api_id
net_workers=self.workers
) )
self.session.start() self.session.start()

View File

@ -60,7 +60,7 @@ class Session:
) )
INITIAL_SALT = 0x616e67656c696361 INITIAL_SALT = 0x616e67656c696361
NET_WORKERS = 4
WAIT_TIMEOUT = 10 WAIT_TIMEOUT = 10
MAX_RETRIES = 5 MAX_RETRIES = 5
ACKS_THRESHOLD = 8 ACKS_THRESHOLD = 8
@ -74,19 +74,15 @@ class Session:
proxy: type, proxy: type,
auth_key: bytes, auth_key: bytes,
api_id: str, api_id: str,
is_cdn: bool = False, is_cdn: bool = False):
net_workers: int = 2):
if not Session.notice_displayed: if not Session.notice_displayed:
print("Pyrogram v{}, {}".format(__version__, __copyright__)) print("Pyrogram v{}, {}".format(__version__, __copyright__))
print("Licensed under the terms of the " + __license__, end="\n\n") print("Licensed under the terms of the " + __license__, end="\n\n")
Session.notice_displayed = True Session.notice_displayed = True
self.is_cdn = is_cdn
self.net_workers = net_workers
self.connection = Connection(DataCenter(dc_id, test_mode), proxy) self.connection = Connection(DataCenter(dc_id, test_mode), proxy)
self.api_id = api_id self.api_id = api_id
self.is_cdn = is_cdn
self.auth_key = auth_key self.auth_key = auth_key
self.auth_key_id = sha1(auth_key).digest()[-8:] self.auth_key_id = sha1(auth_key).digest()[-8:]
@ -120,7 +116,7 @@ class Session:
try: try:
self.connection.connect() self.connection.connect()
for i in range(self.net_workers): for i in range(self.NET_WORKERS):
Thread(target=self.net_worker, name="NetWorker#{}".format(i + 1)).start() Thread(target=self.net_worker, name="NetWorker#{}".format(i + 1)).start()
Thread(target=self.recv, name="RecvThread").start() Thread(target=self.recv, name="RecvThread").start()
@ -179,7 +175,7 @@ class Session:
self.connection.close() self.connection.close()
for i in range(self.net_workers): for i in range(self.NET_WORKERS):
self.recv_queue.put(None) self.recv_queue.put(None)
log.debug("Session stopped") log.debug("Session stopped")