diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index 8b71312d..55f20743 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -352,14 +352,14 @@ class Client(Methods, BaseClient): for _ in range(Client.UPDATES_WORKERS): self.updates_worker_tasks.append( - asyncio.create_task(self.updates_worker()) + asyncio.ensure_future(self.updates_worker()) ) log.info("Started {} UpdatesWorkerTasks".format(Client.UPDATES_WORKERS)) for _ in range(Client.DOWNLOAD_WORKERS): self.download_worker_tasks.append( - asyncio.create_task(self.download_worker()) + asyncio.ensure_future(self.download_worker()) ) log.info("Started {} DownloadWorkerTasks".format(Client.DOWNLOAD_WORKERS)) @@ -1623,7 +1623,7 @@ class Client(Methods, BaseClient): return try: - await asyncio.create_task(session.send(data)) + await asyncio.ensure_future(session.send(data)) except Exception as e: log.error(e) @@ -1644,7 +1644,7 @@ class Client(Methods, BaseClient): file_id = file_id or self.rnd_id() md5_sum = md5() if not is_big and not is_missing_part else None pool = [Session(self, self.storage.dc_id, self.storage.auth_key, is_media=True) for _ in range(pool_size)] - workers = [asyncio.create_task(worker(session)) for session in pool for _ in range(workers_count)] + workers = [asyncio.ensure_future(worker(session)) for session in pool for _ in range(workers_count)] queue = asyncio.Queue(16) try: diff --git a/pyrogram/client/ext/dispatcher.py b/pyrogram/client/ext/dispatcher.py index 855fefe7..d4388ddd 100644 --- a/pyrogram/client/ext/dispatcher.py +++ b/pyrogram/client/ext/dispatcher.py @@ -98,7 +98,7 @@ class Dispatcher: self.locks_list.append(asyncio.Lock()) self.update_worker_tasks.append( - asyncio.create_task(self.update_worker(self.locks_list[-1])) + asyncio.ensure_future(self.update_worker(self.locks_list[-1])) ) log.info("Started {} UpdateWorkerTasks".format(self.workers)) diff --git a/pyrogram/client/ext/syncer.py b/pyrogram/client/ext/syncer.py index bf54f57b..8b48e6e2 100644 --- a/pyrogram/client/ext/syncer.py +++ b/pyrogram/client/ext/syncer.py @@ -59,7 +59,7 @@ class Syncer: @classmethod def start(cls): cls.event.clear() - asyncio.create_task(cls.worker()) + asyncio.ensure_future(cls.worker()) @classmethod def stop(cls): diff --git a/pyrogram/session/session.py b/pyrogram/session/session.py index b1377064..e4699f7d 100644 --- a/pyrogram/session/session.py +++ b/pyrogram/session/session.py @@ -123,8 +123,8 @@ class Session: try: await self.connection.connect() - self.net_worker_task = asyncio.create_task(self.net_worker()) - self.recv_task = asyncio.create_task(self.recv()) + self.net_worker_task = asyncio.ensure_future(self.net_worker()) + self.recv_task = asyncio.ensure_future(self.recv()) self.current_salt = FutureSalt(0, 0, Session.INITIAL_SALT) self.current_salt = FutureSalt( @@ -137,7 +137,7 @@ class Session: self.current_salt = \ (await self._send(functions.GetFutureSalts(num=1), timeout=self.START_TIMEOUT)).salts[0] - self.next_salt_task = asyncio.create_task(self.next_salt()) + self.next_salt_task = asyncio.ensure_future(self.next_salt()) if not self.is_cdn: await self._send( @@ -157,7 +157,7 @@ class Session: timeout=self.START_TIMEOUT ) - self.ping_task = asyncio.create_task(self.ping()) + self.ping_task = asyncio.ensure_future(self.ping()) log.info("Session initialized: Layer {}".format(layer)) log.info("Device: {} - {}".format(self.client.device_model, self.client.app_version)) @@ -351,7 +351,7 @@ class Session: log.warning("Server sent \"{}\"".format(Int.read(BytesIO(packet)))) if self.is_connected.is_set(): - asyncio.create_task(self.restart()) + asyncio.ensure_future(self.restart()) break