Revert "Replace ensure_future usages to create_task"

This reverts commit 9940dd67
This commit is contained in:
Dan 2019-08-03 10:37:48 +02:00
parent 94603f1ff2
commit adda199c77
4 changed files with 11 additions and 11 deletions

View File

@ -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:

View File

@ -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))

View File

@ -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):

View File

@ -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