From 9087f27f2a74a5db7886fd372b600ba3a87c8a44 Mon Sep 17 00:00:00 2001 From: croneter Date: Fri, 21 Dec 2018 16:03:56 +0100 Subject: [PATCH] Optimize code --- resources/lib/plex_functions.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/resources/lib/plex_functions.py b/resources/lib/plex_functions.py index 71eda92d..4596f092 100644 --- a/resources/lib/plex_functions.py +++ b/resources/lib/plex_functions.py @@ -604,9 +604,9 @@ class DownloadGen(object): def __next__(self): while True: - if len(self.xml): - self.current += 1 + try: child = self.xml[0] + self.current += 1 self.xml.remove(child) if (self.current % CONTAINERSIZE == 0 and self.current <= self.total - (self.cache_factor - 1) * CONTAINERSIZE): @@ -614,10 +614,11 @@ class DownloadGen(object): self._download_chunk( start=self.current + (self.cache_factor - 1) * CONTAINERSIZE) return child - app.APP.monitor.waitForAbort(0.1) - if not self.pending_counter and not len(self.xml): - raise StopIteration() + except IndexError: + if not self.pending_counter and not len(self.xml): + raise StopIteration() LOG.debug('Waiting for download to finish') + app.APP.monitor.waitForAbort(0.1) next = __next__