Replace ensure_future usages to create_task

This commit is contained in:
Dan 2019-07-15 00:51:32 +02:00
parent d5f31a8473
commit 9940dd678f
4 changed files with 11 additions and 11 deletions

View File

@ -325,14 +325,14 @@ class Client(Methods, BaseClient):
for _ in range(Client.UPDATES_WORKERS): for _ in range(Client.UPDATES_WORKERS):
self.updates_worker_tasks.append( self.updates_worker_tasks.append(
asyncio.ensure_future(self.updates_worker()) asyncio.create_task(self.updates_worker())
) )
log.info("Started {} UpdatesWorkerTasks".format(Client.UPDATES_WORKERS)) log.info("Started {} UpdatesWorkerTasks".format(Client.UPDATES_WORKERS))
for _ in range(Client.DOWNLOAD_WORKERS): for _ in range(Client.DOWNLOAD_WORKERS):
self.download_worker_tasks.append( self.download_worker_tasks.append(
asyncio.ensure_future(self.download_worker()) asyncio.create_task(self.download_worker())
) )
log.info("Started {} DownloadWorkerTasks".format(Client.DOWNLOAD_WORKERS)) log.info("Started {} DownloadWorkerTasks".format(Client.DOWNLOAD_WORKERS))
@ -1397,7 +1397,7 @@ class Client(Methods, BaseClient):
return return
try: try:
await asyncio.ensure_future(session.send(data)) await asyncio.create_task(session.send(data))
except Exception as e: except Exception as e:
log.error(e) log.error(e)
@ -1418,7 +1418,7 @@ class Client(Methods, BaseClient):
file_id = file_id or self.rnd_id() file_id = file_id or self.rnd_id()
md5_sum = md5() if not is_big and not is_missing_part else None 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)] pool = [Session(self, self.storage.dc_id, self.storage.auth_key, is_media=True) for _ in range(pool_size)]
workers = [asyncio.ensure_future(worker(session)) for session in pool for _ in range(workers_count)] workers = [asyncio.create_task(worker(session)) for session in pool for _ in range(workers_count)]
queue = asyncio.Queue(16) queue = asyncio.Queue(16)
try: try:

View File

@ -98,7 +98,7 @@ class Dispatcher:
self.locks_list.append(asyncio.Lock()) self.locks_list.append(asyncio.Lock())
self.update_worker_tasks.append( self.update_worker_tasks.append(
asyncio.ensure_future(self.update_worker(self.locks_list[-1])) asyncio.create_task(self.update_worker(self.locks_list[-1]))
) )
log.info("Started {} UpdateWorkerTasks".format(self.workers)) log.info("Started {} UpdateWorkerTasks".format(self.workers))

View File

@ -59,7 +59,7 @@ class Syncer:
@classmethod @classmethod
def start(cls): def start(cls):
cls.event.clear() cls.event.clear()
asyncio.ensure_future(cls.worker()) asyncio.create_task(cls.worker())
@classmethod @classmethod
def stop(cls): def stop(cls):

View File

@ -123,8 +123,8 @@ class Session:
try: try:
await self.connection.connect() await self.connection.connect()
self.net_worker_task = asyncio.ensure_future(self.net_worker()) self.net_worker_task = asyncio.create_task(self.net_worker())
self.recv_task = asyncio.ensure_future(self.recv()) self.recv_task = asyncio.create_task(self.recv())
self.current_salt = FutureSalt(0, 0, Session.INITIAL_SALT) self.current_salt = FutureSalt(0, 0, Session.INITIAL_SALT)
self.current_salt = FutureSalt( self.current_salt = FutureSalt(
@ -137,7 +137,7 @@ class Session:
self.current_salt = \ self.current_salt = \
(await self._send(functions.GetFutureSalts(num=1), timeout=self.START_TIMEOUT)).salts[0] (await self._send(functions.GetFutureSalts(num=1), timeout=self.START_TIMEOUT)).salts[0]
self.next_salt_task = asyncio.ensure_future(self.next_salt()) self.next_salt_task = asyncio.create_task(self.next_salt())
if not self.is_cdn: if not self.is_cdn:
await self._send( await self._send(
@ -157,7 +157,7 @@ class Session:
timeout=self.START_TIMEOUT timeout=self.START_TIMEOUT
) )
self.ping_task = asyncio.ensure_future(self.ping()) self.ping_task = asyncio.create_task(self.ping())
log.info("Session initialized: Layer {}".format(layer)) log.info("Session initialized: Layer {}".format(layer))
log.info("Device: {} - {}".format(self.client.device_model, self.client.app_version)) 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)))) log.warning("Server sent \"{}\"".format(Int.read(BytesIO(packet))))
if self.is_connected.is_set(): if self.is_connected.is_set():
asyncio.ensure_future(self.restart()) asyncio.create_task(self.restart())
break break