Don't spawn unnecessary threads when no_updates=True

This commit is contained in:
Dan 2020-03-30 17:33:28 +02:00
parent 2ba921c84d
commit 8681ca2043

View File

@ -216,7 +216,7 @@ class Client(Methods, BaseClient):
else: else:
raise ValueError("Unknown storage engine") raise ValueError("Unknown storage engine")
self.dispatcher = Dispatcher(self, workers) self.dispatcher = Dispatcher(self, 0 if no_updates else workers)
def __enter__(self): def __enter__(self):
return self.start() return self.start()
@ -302,15 +302,16 @@ class Client(Methods, BaseClient):
self.load_plugins() self.load_plugins()
for i in range(self.UPDATES_WORKERS): if not self.no_updates:
self.updates_workers_list.append( for i in range(self.UPDATES_WORKERS):
Thread( self.updates_workers_list.append(
target=self.updates_worker, Thread(
name="UpdatesWorker#{}".format(i + 1) target=self.updates_worker,
name="UpdatesWorker#{}".format(i + 1)
)
) )
)
self.updates_workers_list[-1].start() self.updates_workers_list[-1].start()
for i in range(self.DOWNLOAD_WORKERS): for i in range(self.DOWNLOAD_WORKERS):
self.download_workers_list.append( self.download_workers_list.append(
@ -355,13 +356,14 @@ class Client(Methods, BaseClient):
self.download_workers_list.clear() self.download_workers_list.clear()
for _ in range(self.UPDATES_WORKERS): if not self.no_updates:
self.updates_queue.put(None) for _ in range(self.UPDATES_WORKERS):
self.updates_queue.put(None)
for i in self.updates_workers_list: for i in self.updates_workers_list:
i.join() i.join()
self.updates_workers_list.clear() self.updates_workers_list.clear()
for i in self.media_sessions.values(): for i in self.media_sessions.values():
i.stop() i.stop()