From 26e828b9566ed3ba13b47705c0df488514ca91e8 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 18 Jun 2018 21:21:26 +0200 Subject: [PATCH] Make BaseClient asynchronous and default DOWNLOAD_WORKERS to 4 --- pyrogram/client/ext/base_client.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/pyrogram/client/ext/base_client.py b/pyrogram/client/ext/base_client.py index 9c0fb26b..04a6ac12 100644 --- a/pyrogram/client/ext/base_client.py +++ b/pyrogram/client/ext/base_client.py @@ -16,9 +16,8 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +import asyncio import re -from queue import Queue -from threading import Lock from ..style import Markdown, HTML from ...api.core import Object @@ -30,7 +29,7 @@ class BaseClient: BOT_TOKEN_RE = re.compile(r"^\d+:[\w-]+$") DIALOGS_AT_ONCE = 100 UPDATES_WORKERS = 1 - DOWNLOAD_WORKERS = 1 + DOWNLOAD_WORKERS = 4 OFFLINE_SLEEP = 300 MEDIA_TYPE_ID = { @@ -65,15 +64,15 @@ class BaseClient: self.session = None self.media_sessions = {} - self.media_sessions_lock = Lock() + self.media_sessions_lock = asyncio.Lock() self.is_started = None self.is_idle = None - self.updates_queue = Queue() - self.updates_workers_list = [] - self.download_queue = Queue() - self.download_workers_list = [] + self.updates_queue = asyncio.Queue() + self.updates_worker_task = None + self.download_queue = asyncio.Queue() + self.download_worker_tasks = [] self.disconnect_handler = None